Upgrade to Pro — share decks privately, control downloads, hide ads and more …

「CPUとは何か」をPHPで考える / What is a CPU?

「CPUとは何か」をPHPで考える / What is a CPU?

PHPカンファレンス 2019 の発表資料です

HASEGAWA Tomoki

December 01, 2019
Tweet

More Decks by HASEGAWA Tomoki

Other Decks in Technology

Transcript

  1. લ࠲
    લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ

    View full-size slide

  2. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    σδλϧճ࿏

    View full-size slide

  3. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    σδλϧճ࿏
    wʮίϯϐϡʔλ͸͢΂ͯΛͱͰදݱ͢Δʯ

    View full-size slide

  4. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    σδλϧճ࿏
    wʮίϯϐϡʔλ͸͢΂ͯΛͱͰදݱ͢Δʯ
    wʮʯ
    ʮʯͱ͸ʁ

    View full-size slide

  5. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    σδλϧճ࿏
    wʮίϯϐϡʔλ͸͢΂ͯΛͱͰදݱ͢Δʯ
    wʮʯ
    ʮʯͱ͸ʁ
    wόΠφϦਐ਺‎ਐ਺

    View full-size slide

  6. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    σδλϧճ࿏
    wʮίϯϐϡʔλ͸͢΂ͯΛͱͰදݱ͢Δʯ
    wʮʯ
    ʮʯͱ͸ʁ
    wόΠφϦਐ਺‎ਐ਺
    wσδλϧճ࿏Ͱ͸ిѹͷߴ௿

    View full-size slide

  7. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ

    View full-size slide

  8. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ

    View full-size slide

  9. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    )$

    View full-size slide

  10. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    )$
    /"/%ճ࿏

    View full-size slide

  11. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    "
    #
    :
    ೖྗ ग़ྗ
    "
    #
    :

    View full-size slide

  12. ؆ུԽ͍ͯ͠·͢ɻ࣮ࡍʹ͸఍߅͕ඞཁͰ͢

    View full-size slide

  13. ؆ུԽ͍ͯ͠·͢ɻ࣮ࡍʹ͸఍߅͕ඞཁͰ͢

    View full-size slide

  14. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    "
    #
    :
    ೖྗ ग़ྗ
    "
    # :

    View full-size slide

  15. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    "
    #
    :
    ೖྗ ग़ྗ
    "
    # :

    View full-size slide

  16. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    "
    #
    :
    ೖྗ ग़ྗ
    "
    # :

    View full-size slide

  17. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    "
    #
    :
    ೖྗ ग़ྗ
    "
    # :

    View full-size slide

  18. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    ೖྗ ग़ྗ
    "
    # :

    View full-size slide

  19. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    ೖྗ ग़ྗ
    "
    # :

    View full-size slide

  20. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    ೖྗ ग़ྗ
    "
    # :
    7

    View full-size slide

  21. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    ೖྗ ग़ྗ
    "
    # :
    7
    7

    View full-size slide

  22. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    ೖྗ ग़ྗ
    "
    # :
    7
    7
    7

    View full-size slide

  23. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    ೖྗ ग़ྗ
    "
    # :
    7
    7
    7

    View full-size slide

  24. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    ೖྗ ग़ྗ
    "
    # :
    7
    7
    7
    7

    View full-size slide

  25. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    ೖྗ ग़ྗ
    "
    # :

    View full-size slide

  26. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    ೖྗ ग़ྗ
    "
    # :
    7

    View full-size slide

  27. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    ೖྗ ग़ྗ
    "
    # :
    7
    7

    View full-size slide

  28. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    ೖྗ ग़ྗ
    "
    # :
    7
    7
    7

    View full-size slide

  29. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    ೖྗ ग़ྗ
    "
    # :
    7
    7
    7

    View full-size slide

  30. લ࠲ ʙʮ$16ͱ͸Կ͔ʯ
    Λ1)1Ͱߟ͑Δ
    ೖྗ ग़ྗ
    "
    # :
    7
    7
    7
    7

    View full-size slide

  31. $16ͱ͸Կ͔
    ̘̥̪

    View full-size slide

  32. ௕୩઒ஐر
    ʮ$16ͱ͸Կ͔ʯ
    Λ
    1)1Ͱߟ͑Δ

    View full-size slide

  33. ௕୩઒ஐر
    !UPN[PI

    View full-size slide

  34. ௕୩઒ஐر
    !UPN[PI

    ϋογϡ

    View full-size slide

  35. ௕୩઒ஐر
    !UPN[PI

    ϋογϡ

    ήʔϜϘʔΠΤϛϡϨʔλ

    View full-size slide

  36. ௕୩઒ஐر
    4PGUXBSF%FTJHO೥݄߸
    ʮ$16ͱ͸ԿͩΖ͏͔ʯ
    ΈΜͳͷ1)1
    ʮ1)1ʹΑΔϑΝϛίϯΤϛϡϨʔλͷ࣮૷ʯ
    !UPN[PI

    View full-size slide

  37. ௕୩઒ஐر
    !UPN[PI

    View full-size slide

  38. ϥΠϑϫʔΫ
    ςοΫΧϯϑΝϨϯεӡӦࢀՃ
    8FCJ04ΞϓϦ։ൃ Ϗʔϧ
    $16 ϨτϩήʔϜػ ిࢠ޻࡞
    αοΧʔ؍ઓ
    ϨϯλϧΧʔτϨʔε ʜ
    σδλϧαʔΧεגࣜձࣾ
    ෭ஂ௕$50
    !UPN[PI

    View full-size slide

  39. 8FC%FWFMPQNFOUXJUI
    8&"3&)*3*/(
    IUUQXXXEHDJSDVTDPN
    ౦ژදࢀಓ

    View full-size slide

  40. τʔΫԠืͨ͠ʁ
    ͸͍
    ͍͍͑

    View full-size slide

  41. τʔΫԠืͨ͠ʁ
    ͸͍
    ͍͍͑

    View full-size slide

  42. τʔΫԠืͨ͠ʁ
    ͸͍
    ͍͍͑
    ໌೔ʒ੾Ͱ͢ʂ
    ࠓ೔౤ߘͯ͠ʂ

    View full-size slide

  43. ࠓ೔ͷςʔϚ

    View full-size slide

  44. ௕୩઒ஐر
    ʮ$16ͱ͸Կ͔ʯ
    Λ
    1)1Ͱߟ͑Δ

    View full-size slide

  45. ௕୩઒ஐر
    ʮ$16ͱ͸Կ͔ʯ
    Λ
    1)1Ͱߟ͑Δ
    ʘͭͷࢹ఺͔Βݟͨ$16ʗ

    View full-size slide

  46. ࢹ఺ ϓϩάϥϜ࣮ߦ؀ڥ

    View full-size slide

  47. ࢹ఺ ϓϩάϥϜ࣮ߦ؀ڥ
    ࢹ఺ ΤϛϡϨʔτର৅

    View full-size slide

  48. ࢹ఺ ϓϩάϥϜ࣮ߦ؀ڥ
    ࢹ఺ ΤϛϡϨʔτର৅
    ࢹ఺ ిؾճ࿏

    View full-size slide

  49. ୊ࡐ$16 5%

    View full-size slide

  50. $16ͷ૑Γ͔ͨʢॻ੶ʣ

    View full-size slide

  51. $16ͷ૑Γ͔ͨʢॻ੶ʣ
    ʘ໊ஶʗ

    View full-size slide

  52. IUUQTXXXBNB[PODPKQEQ

    View full-size slide

  53. IUUQTXXXBNB[PODPKQEQ

    View full-size slide

  54. IUUQTXXXBNB[PODPKQEQ

    View full-size slide

  55. IUUQTXXXBNB[PODPKQEQ
    'Ͱചͬͯ·͢ɻ
    ങ͓͏ʂʢ࡭ʣ

    View full-size slide

  56. ͖͍࣋ͬͯͯΔͷͰ
    ࠙਌ձͱ͔Ͱ੠͔͚͍ͯͩ͘͞

    View full-size slide

  57. ୊ࡐ$16 5%

    View full-size slide

  58. ϓϩάϥϜ࣮ߦ؀ڥ
    ࢹ఺
    ͱͯ͠ͷ$16

    View full-size slide

  59. Έͳ͞Μ͓ೃછΈ

    View full-size slide

  60. ;JMPH;
    :".")"
    :.

    View full-size slide

  61. ϓϩάϥϜ࣮ߦ؀ڥͱͯ͠ͷ$16

    View full-size slide

  62. ϓϩάϥϜ࣮ߦ؀ڥͱͯ͠ͷ$16
    wϚγϯޠϓϩάϥϜͷ࣮ߦ؀ڥ

    View full-size slide

  63. ϓϩάϥϜ࣮ߦ؀ڥͱͯ͠ͷ$16
    wϚγϯޠϓϩάϥϜͷ࣮ߦ؀ڥ
    wVTSCJOQIQϚγϯޠϓϩάϥϜ

    View full-size slide

  64. ϓϩάϥϜ࣮ߦ؀ڥͱͯ͠ͷ$16
    wϚγϯޠϓϩάϥϜͷ࣮ߦ؀ڥ
    wVTSCJOQIQϚγϯޠϓϩάϥϜ
    w$ݴޠ‎χʔϞχοΫ‎Ϛγϯޠ
    ίϯύΠϧ Ξηϯϒϧ

    View full-size slide

  65. 5%ͷϚγϯޠ

    View full-size slide

  66. 5%ͷϚγϯޠ
    wϏοτͷ໋ྩϏοτͷҾ਺

    View full-size slide

  67. 5%ͷϚγϯޠ
    wϏοτͷ໋ྩϏοτͷҾ਺
    ʢΦϖίʔυʣ ʢΦϖϥϯυʣ

    View full-size slide

  68. 5%ͷϚγϯޠ
    wϏοτͷ໋ྩϏοτͷҾ਺
    w໋ྩόΠτ
    ʢΦϖίʔυʣ ʢΦϖϥϯυʣ

    View full-size slide

  69. 5%ͷϚγϯޠ
    wϏοτͷ໋ྩϏοτͷҾ਺
    w໋ྩόΠτ
    w໋ྩΛϝϞϦʹ֨ೲ͞Εͨॱ൪ʹ࣮ߦ͢Δ
    ʢΦϖίʔυʣ ʢΦϖϥϯυʣ

    View full-size slide

  70. 5%ͷϚγϯޠ
    wϏοτͷ໋ྩϏοτͷҾ਺
    w໋ྩόΠτ
    w໋ྩΛϝϞϦʹ֨ೲ͞Εͨॱ൪ʹ࣮ߦ͢Δ
    ʢΦϖίʔυʣ ʢΦϖϥϯυʣ

    View full-size slide

  71. 5%ͷϚγϯޠ

    View full-size slide

  72. 5%ͷϚγϯޠ
    Φϖίʔυ

    Φϖϥϯυʢ*Nʣ


    View full-size slide

  73. 5%ͷϚγϯޠ
    Φϖίʔυ

    Φϖϥϯυʢ*Nʣ


    "%%" *N

    View full-size slide

  74. 5%ͷϚγϯޠ
    Φϖίʔυ

    Φϖϥϯυʢ*Nʣ


    "Ϩδελʹ*Nͷ஋Λ଍͢
    "%%" *N

    View full-size slide

  75. 5%ͷϚγϯޠ
    Φϖίʔυ

    Φϖϥϯυʢ*Nʣ


    ""
    "Ϩδελʹ*Nͷ஋Λ଍͢
    "%%" *N

    View full-size slide

  76. 5%ͷ໋ྩηοτ
    ໋ྩ
    ʢχʔϞχοΫʣ
    ಈ࡞
    0QDPEF
    ʢਐʣ
    0QDPEF
    ʢਐʣ
    "%%" *N "Ϩδελʹ*NΛ଍͢ C Y
    .07" # #Ϩδελͷ஋Λ"Ϩδελʹసૹ͢Δ C Y
    */" *0ϙʔτ͔Β"Ϩδελʹ஋ΛಡΈࠐΉ C Y
    .07" *N "Ϩδελʹ*Nͷ஋Λసૹ͢Δ C Y
    +.1*N *Nʹδϟϯϓ͢Δ C YG

    View full-size slide

  77. 5%ͷ໋ྩηοτ
    ໋ྩ
    ʢχʔϞχοΫʣ
    ಈ࡞
    0QDPEF
    ʢਐʣ
    0QDPEF
    ʢਐʣ
    "%%" *N "Ϩδελʹ*NΛ଍͢ C Y
    .07" # #Ϩδελͷ஋Λ"Ϩδελʹసૹ͢Δ C Y
    */" *0ϙʔτ͔Β"Ϩδελʹ஋ΛಡΈࠐΉ C Y
    .07" *N "Ϩδελʹ*Nͷ஋Λసૹ͢Δ C Y
    +.1*N *Nʹδϟϯϓ͢Δ C YG
    શ໋ྩ

    View full-size slide

  78. 5%ͷϚγϯޠϓϩάϥϜ
    ΞυϨε όΠφϦ ໋ྩ ҙຯ
    # 065 065ϙʔτʹYYYY
    # 065 Λग़ྗ͢Δ
    # 065
    # 065
    # 065
    # 065
    ' +.1 ʹδϟϯϓ͢Δ

    View full-size slide

  79. 065*NYYYY

    +.1*NYYYY

    View full-size slide

  80. 065*NYYYY

    +.1*NYYYY

    View full-size slide

  81. 065*NYYYY

    +.1*NYYYY

    065ϙʔτ

    View full-size slide

  82. ಈ࡞ΛݟͯΈΑ͏

    View full-size slide

  83. ϓϩάϥϜ࣮ߦ؀ڥͱͯ͠$16
    Λݟͨ࣌ͷߟ͑ํ

    View full-size slide

  84. ϓϩάϥϜ࣮ߦ؀ڥͱͯ͠$16
    wϓϩάϥϜΛ࣮ߦͯ͘͠ΕΔଘࡏ
    ʢ˺ݴޠʣ
    Λݟͨ࣌ͷߟ͑ํ

    View full-size slide

  85. ϓϩάϥϜ࣮ߦ؀ڥͱͯ͠$16
    wϓϩάϥϜΛ࣮ߦͯ͘͠ΕΔଘࡏ
    ʢ˺ݴޠʣ
    Λݟͨ࣌ͷߟ͑ํ
    wࣗ෼ͷ࢖͏ػೳͷΈͷཧղͰ0,
    ʢ͢΂ͯͷ໋ྩɾ࢓༷Λ஌Δඞཁ͸ແ͍ʣ

    View full-size slide

  86. $16ͱ͸Կ͔
    ̘̥̪

    View full-size slide

  87. ΤϛϡϨʔτର৅
    ࢹ఺
    ͱͯ͠ͷ$16

    View full-size slide

  88. ΤϛϡϨʔτର৅ͱͯ͠ͷ$16
    wΤϛϡϨʔλͷ$16෦෼

    View full-size slide

  89. ΤϛϡϨʔτର৅ͱͯ͠ͷ$16
    w$16ͷ;Δ·͍Λ
    ιϑτ΢ΣΞͱ࣮ͯ͠૷
    wΤϛϡϨʔλͷ$16෦෼

    View full-size slide

  90. 1)1Ͱ࣮૷ͯ͠ΈΔ

    View full-size slide

  91. ϝϞϦͷ࣮૷
    ໋ྩͷ࣮૷
    *0ͷ࣮૷

    View full-size slide

  92. ϝϞϦͱ͸ͲΜͳ΋ͷʁ
    wΞυϨεʢ൪஍ʣ͝ͱʹόΠτͷσʔλΛ
    อ࣋͢ΔσόΠε

    View full-size slide

  93. ϝϞϦͱ͸ͲΜͳ΋ͷʁ
    wΞυϨεʢ൪஍ʣ͝ͱʹόΠτͷσʔλΛ
    อ࣋͢ΔσόΠε
    ΞυϨε όΠφϦ ໋ྩ ҙຯ
    # 065 065ϙʔτʹYYYY
    # 065 Λग़ྗ͢Δ
    # 065
    # 065
    # 065
    # 065
    ' +.1 ʹδϟϯϓ͢Δ

    View full-size slide

  94. ϝϞϦͱ͸ͲΜͳ΋ͷʁ
    wΞυϨεʢ൪஍ʣ͝ͱʹόΠτͷσʔλΛ
    อ࣋͢ΔσόΠε

    View full-size slide

  95. ϝϞϦͱ͸ͲΜͳ΋ͷʁ
    w$16͸ΞυϨεΛࢦఆͯ͠σʔλΛಡΈॻ͖͢Δ
    wΞυϨεʢ൪஍ʣ͝ͱʹόΠτͷσʔλΛ
    อ࣋͢ΔσόΠε

    View full-size slide

  96. ϝϞϦͱ͸ͲΜͳ΋ͷʁ
    w$16͸ΞυϨεΛࢦఆͯ͠σʔλΛಡΈॻ͖͢Δ
    wΞυϨεʢ൪஍ʣ͝ͱʹόΠτͷσʔλΛ
    อ࣋͢ΔσόΠε
    w30.΋3".΋$16Ωϟογϡ΋
    44%΋)%%΋ࢴςʔϓ΋޿ٛͷϝϞϦɻ
    ҧ͍͸ʢ෺ཧతͳʣେ͖͞ɾ଎౓ɾՁ֨ɻ

    View full-size slide

  97. Ͳͷ༷ʹϝϞϦΛදݱ͢Δʁ
    ΞυϨε όΠφϦ ໋ྩ ҙຯ
    # 065 065ϙʔτʹYYYY
    # 065 Λग़ྗ͢Δ
    # 065
    # 065
    # 065
    # 065
    ' +.1 ʹδϟϯϓ͢Δ

    View full-size slide

  98. Ͳͷ༷ʹϝϞϦΛදݱ͢Δʁ
    ΞυϨε όΠφϦ ໋ྩ ҙຯ
    # 065 065ϙʔτʹYYYY
    # 065 Λग़ྗ͢Δ
    # 065
    # 065
    # 065
    # 065
    ' +.1 ʹδϟϯϓ͢Δ
    21)1ʹɺ͜ΕΛදݱ͢Δͷʹ
    ϐολϦͷݴޠ࢓༷͕
    ͋Γ·͢ΑͶɻԿͰ͠ΐ͏ʁ

    View full-size slide

  99. ഑ྻ
    ͨ͑͜

    View full-size slide

  100. ఴࣈΞυϨε
    ஋όΠτͷϚγϯޠ
    ഑ྻ
    ͨ͑͜

    View full-size slide

  101. class Cpu
    {
    private $ram;
    }
    ϝϞϦͷ࣮૷

    View full-size slide

  102. class Cpu
    {
    public function __construct()
    {
    $this->ram = array_fill(0, 0b1111, 0);
    $this->pc = $this->a = $this->b = 0;
    }
    private $ram;
    private $pc;
    private $a;
    private $b;
    ϝϞϦͷॳظԽͱϨδελͷ࣮૷

    View full-size slide

  103. ϝϞϦͷ࣮૷
    ໋ྩͷ࣮૷
    *0ͷ࣮૷

    View full-size slide

  104. 5%ͷϚγϯޠ
    0QDPEF

    *Nʢ0QFSBOE



    ""
    "Ϩδελʹ*Nͷ஋Λ଍͢
    "%%" *N

    View full-size slide

  105. public function executeInstruction()
    {

    View full-size slide

  106. public function executeInstruction()
    {
    $byte = $this->ram[$this->pc];

    View full-size slide

  107. public function executeInstruction()
    {
    $byte = $this->ram[$this->pc];
    1$ϓϩάϥϜΧ΢ϯλ

    View full-size slide

  108. public function executeInstruction()
    {
    $byte = $this->ram[$this->pc];
    1$ϓϩάϥϜΧ΢ϯλ
    ࣮ߦதͷΞυϨε

    View full-size slide

  109. public function executeInstruction()
    {
    $byte = $this->ram[$this->pc];

    View full-size slide

  110. public function executeInstruction()
    {
    $byte = $this->ram[$this->pc];
    0QDPEF

    *Nʢ0QFSBOE


    View full-size slide

  111. $opcode = $byte >> 4;
    $im = $byte & 0b00001111;
    public function executeInstruction()
    {
    $byte = $this->ram[$this->pc];
    0QDPEF

    *Nʢ0QFSBOE


    View full-size slide

  112. $opcode = $byte >> 4;
    $im = $byte & 0b00001111;
    public function executeInstruction()
    {
    $byte = $this->ram[$this->pc];

    View full-size slide

  113. $opcode = $byte >> 4;
    $im = $byte & 0b00001111;
    public function executeInstruction()
    {
    switch ($opcode){
    case 0b0000:
    // ADD A, Im
    $this->a += $im;
    break;
    }
    $byte = $this->ram[$this->pc];

    View full-size slide

  114. $opcode = $byte >> 4;
    $im = $byte & 0b00001111;
    public function executeInstruction()
    {
    switch ($opcode){
    case 0b0000:
    // ADD A, Im
    $this->a += $im;
    break;
    }
    $byte = $this->ram[$this->pc];
    case 0b0001:

    View full-size slide

  115. $opcode = $byte >> 4;
    $im = $byte & 0b00001111;
    public function executeInstruction()
    {
    switch ($opcode){
    case 0b0000:
    // ADD A, Im
    $this->a += $im;
    break;
    }
    $this->pc++;
    }
    $byte = $this->ram[$this->pc];
    case 0b0001:

    View full-size slide

  116. ϝϞϦͷ࣮૷
    ໋ྩͷ࣮૷
    *0ͷ࣮૷

    View full-size slide

  117. case 0b0110:
    // IN B
    $this->b = $this->in;
    break;

    View full-size slide

  118. case 0b0110:
    // IN B
    $this->b = $this->in;
    break;
    case 0b1001:
    // OUT B
    $this->out = $this->b;
    break;

    View full-size slide

  119. case 0b0110:
    // IN B
    $this->b = $this->in;
    break;
    case 0b1001:
    // OUT B
    $this->out = $this->b;
    break;
    case 0b1011:
    // OUT Im
    $this->out = $operand;
    break;

    View full-size slide

  120. DQVOFX5Ea$QV

    do {
    printf("PC: 0b%04b > ", $cpu->pc);
    $stdin = fgets(STDIN);
    $cpu->in = bindec($stdin);
    $cpu->executeInstruction();
    printf("IN: 0b%04b OUT: 0b%04b\n",
    $cpu->in, $cpu->out);
    } while(true);

    View full-size slide

  121. IUUQTHJUIVCDPNIBTFHBXBUPNPLJQIQUFSNJOBMUEFNVMBUPS

    View full-size slide

  122. ಈ࡞ΛΈͯΈΑ͏

    View full-size slide

  123. ΤϛϡϨʔτର৅ͱͯ͠$16
    Λݟͨ࣌ͷߟ͑ํ

    View full-size slide

  124. ΤϛϡϨʔτର৅ͱͯ͠$16
    Λݟͨ࣌ͷߟ͑ํ
    wର৅$16༻ʹॻ͔Εͨ
    શͯͷϓϩάϥϜΛಈ࡞ͤ͞Δଘࡏ

    View full-size slide

  125. ΤϛϡϨʔτର৅ͱͯ͠$16
    w$16࢓༷ͷ׬શͳཧղ
    Λݟͨ࣌ͷߟ͑ํ
    wର৅$16༻ʹॻ͔Εͨ
    શͯͷϓϩάϥϜΛಈ࡞ͤ͞Δଘࡏ

    View full-size slide

  126. QIQ
    SFRVJSF@PODFWFOEPSBVUPMPBEQIQ
    DQVOFX5Ea$QV

    DQVSBN<
    C
    C
    C
    C
    C
    C
    C



    >
    EP\
    NBJOMPPQ
    ^XIJMF USVF

    View full-size slide

  127. QIQ
    SFRVJSF@PODFWFOEPSBVUPMPBEQIQ
    DQVOFX5Ea$QV

    DQVSBN<
    C
    C
    C
    C
    C
    C
    C



    >
    EP\
    NBJOMPPQ
    ^XIJMF USVF

    View full-size slide

  128. QIQ
    SFRVJSF@PODFWFOEPSBVUPMPBEQIQ
    DQVOFX5Ea$QV

    DQVSBN<
    C
    C
    C
    C
    C
    C
    C



    >
    EP\
    NBJOMPPQ
    ^XIJMF USVF

    ϝϞϦʹϓϩάϥϜΛ
    ಡΈࠐΜͰ͍Δ

    View full-size slide

  129. QIQ
    SFRVJSF@PODFWFOEPSBVUPMPBEQIQ
    DQVOFX5Ea$QV

    DQVSBN<
    C
    C
    C
    C
    C
    C
    C



    >
    EP\
    NBJOMPPQ
    ^XIJMF USVF

    ϝϞϦʹϓϩάϥϜΛ
    ಡΈࠐΜͰ͍Δ
    04ͷ໾ׂ

    View full-size slide

  130. $16ͱ͸Կ͔
    ̘̥̪

    View full-size slide

  131. ిؾճ࿏
    ࢹ఺
    ͱͯ͠ͷ$16

    View full-size slide

  132. $16Λϋʔυ΢ΣΞͱ࣮ͯ͠૷
    ͢Δ৔߹ͷߟ͑ํ

    View full-size slide

  133. 5%ͷ$16໋ྩ

    View full-size slide

  134. 5%ͷ$16໋ྩ
    ͍Ζ͍Ζͳ໋ྩ͕͋Δ͕
    ͭ·Δͱ͜Ζ

    View full-size slide

  135. Կ͔ͱԿ͔Λ଍ͯ͠
    Ͳ͔͜ʹసૹ͢Δ
    5%ͷ$16໋ྩ
    ͍Ζ͍Ζͳ໋ྩ͕͋Δ͕
    ͭ·Δͱ͜Ζ

    View full-size slide

  136. "%%" *Nͷ৔߹
    0QDPEF

    *Nʢ0QFSBOE



    "Ϩδελʹ*Nͷ஋Λ଍͢
    "%%" *N

    View full-size slide

  137. "%%" *Nͷ৔߹
    0QDPEF

    *Nʢ0QFSBOE



    ""
    "Ϩδελʹ*Nͷ஋Λ଍͢
    "%%" *N

    View full-size slide

  138. .07" #ͷ৔߹
    0QDPEF

    *Nʢ0QFSBOE



    "Ϩδελʹ#Ϩδελͷ஋Λ
    సૹ͢Δ
    .07" #

    View full-size slide

  139. .07" #ͷ৔߹
    0QDPEF

    *Nʢ0QFSBOE



    "Ϩδελʹ#Ϩδελͷ஋Λ
    సૹ͢Δ
    .07" #
    "#

    View full-size slide

  140. 5%ͷճ࿏ߏ੒

    View full-size slide

  141. ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔
    */
    ϙʔτ
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ

    View full-size slide

  142. ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔
    */
    ϙʔτ
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ

    View full-size slide

  143. */
    ϙʔτ
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔

    View full-size slide

  144. */
    ϙʔτ
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔

    View full-size slide

  145. */
    ϙʔτ
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔

    View full-size slide

  146. */
    ϙʔτ
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    0QDPEF

    *Nʢ0QFSBOE


    ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔

    View full-size slide

  147. */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    0QDPEF

    *Nʢ0QFSBOE


    ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔

    View full-size slide

  148. */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔

    View full-size slide

  149. */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔

    View full-size slide

  150. */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔

    View full-size slide

  151. ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔
    */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ

    View full-size slide

  152. ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔
    */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    ͦΕΛͲ͏ܾΊΔʁ

    View full-size slide

  153. ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔
    */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    ͦΕΛͲ͏ܾΊΔʁ
    ͦΕ໋͕ͦ͜ྩͳͷͩʂ

    View full-size slide

  154. ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔
    */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    ͦΕΛͲ͏ܾΊΔʁ
    ͦΕ໋͕ͦ͜ྩͳͷͩʂ
    0QDPEF

    *Nʢ0QFSBOE


    View full-size slide

  155. ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔
    */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    0QDPEF

    *Nʢ0QFSBOE


    View full-size slide

  156. ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔
    ্ҐCJU
    */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    0QDPEF

    *Nʢ0QFSBOE


    View full-size slide

  157. ԿͱԿΛ଍ͯ͠Ͳ͜ʹసૹ͢Δ͔
    ্ҐCJU
    */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    0QDPEF

    *Nʢ0QFSBOE


    View full-size slide

  158. ੩తճ࿏Λॲཧ૷ஔԽ͢Δଘࡏ

    View full-size slide

  159. ্ҐCJU
    */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ

    View full-size slide

  160. ্ҐCJU
    */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ

    View full-size slide

  161. ΫϩοΫ
    ্ҐCJU
    */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ

    View full-size slide

  162. ΫϩοΫ
    ্ҐCJU
    */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    1$

    View full-size slide

  163. ΫϩοΫ
    ্ҐCJU
    */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    1$
    1$

    View full-size slide

  164. ΫϩοΫ
    ্ҐCJU
    */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    1$
    1$
    1$

    View full-size slide

  165. ΫϩοΫ
    ্ҐCJU
    */
    ϙʔτ
    ԼҐCJU
    "
    Ϩδελ
    #
    Ϩδελ
    065
    ϙʔτ
    1$
    Ϩδελ
    Ճࢉػ
    ϝϞϦ
    ηϨΫλ
    1$
    1$
    1$

    View full-size slide

  166. ిؾճ࿏ͱͯ͠$16
    Λݟͨ࣌ͷߟ͑ํ

    View full-size slide

  167. ిؾճ࿏ͱͯ͠$16
    wΫϩοΫʹैͬͯঢ়ଶભҠ͢Δճ࿏ͱͯ͠
    $16໋ྩΛදݱͨ͠ଘࡏ
    Λݟͨ࣌ͷߟ͑ํ

    View full-size slide

  168. ిؾճ࿏ͱͯ͠$16
    wΫϩοΫʹैͬͯঢ়ଶભҠ͢Δճ࿏ͱͯ͠
    $16໋ྩΛදݱͨ͠ଘࡏ
    Λݟͨ࣌ͷߟ͑ํ
    w࢓༷ͱ෺ཧͷύζϧΛղ͍ͯ$16࢓༷Λ
    ૑Γ͋͛Δ

    View full-size slide

  169. $16ͱ͸Կ͔
    ̘̥̪

    View full-size slide

  170. ·ͱΊ
    w$16ͱݴͬͯ΋ͲΜͳཱ৔ͰͦΕΛ
    ݟΔ͔ʹΑͬͯݟ͑ํ͕ҧ͏ʂ

    View full-size slide

  171. ·ͱΊ
    w$16ͱݴͬͯ΋ͲΜͳཱ৔ͰͦΕΛ
    ݟΔ͔ʹΑͬͯݟ͑ํ͕ҧ͏ʂ
    wΤϛϡϨʔλ͸೉͍͠΋ͷͰ͸ͳ͍Ͷʂ

    View full-size slide

  172. ·ͱΊ
    w$16ͱݴͬͯ΋ͲΜͳཱ৔ͰͦΕΛ
    ݟΔ͔ʹΑͬͯݟ͑ํ͕ҧ͏ʂ
    wΤϛϡϨʔλ͸೉͍͠΋ͷͰ͸ͳ͍Ͷʂ
    w$16ࣗ࡞΋໘ന͍Αʂ

    View full-size slide

  173. ·ͱΊ
    w$16ͱݴͬͯ΋ͲΜͳཱ৔ͰͦΕΛ
    ݟΔ͔ʹΑͬͯݟ͑ํ͕ҧ͏ʂ
    wΤϛϡϨʔλ͸೉͍͠΋ͷͰ͸ͳ͍Ͷʂ
    w$16ࣗ࡞΋໘ന͍Αʂ
    w΍ͬͯΈΑ͏ʂ

    View full-size slide

  174. ͓ΘΓ
    !UPN[PI

    View full-size slide

  175. ͓ΘΓ
    !UPN[PI

    View full-size slide

  176. 5%ͷϓϩάϥϜผWFS

    View full-size slide

  177. ϚγϯޠͰॻ͔ΕͨϓϩάϥϜ

    View full-size slide

  178. ϚγϯޠͰॻ͔ΕͨϓϩάϥϜ
    YG

    View full-size slide

  179. Y .07" "ϨδελʹΛసૹ
    Y "%%" "ϨδελʹΛ଍͢
    Y .07# " #Ϩδελʹ"Ϩδελͷ
    ஋Λసૹ
    Y 065# #Ϩδελͷ஋Λ*0
    ϙʔτʹग़ྗ
    Y ' +.1Y Yʹδϟϯϓ
    ϚγϯޠͰॻ͔ΕͨϓϩάϥϜ

    View full-size slide

  180. ͓ΘΓ
    !UPN[PI

    View full-size slide