Advertisement
Guest User

Untitled

a guest
Dec 7th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. >>>>Data Structure:
  2.  
  3. Registers:
  4.  
  5. 0 7 15
  6. | | |
  7.  
  8. |----------------| -\
  9. | A | |
  10. |----------------| |
  11.  
  12. |----------------| |
  13. | B | |
  14. |----------------| |
  15.  
  16. |----------------| \
  17. | C | - General Purpose Registers
  18. |----------------| /
  19.  
  20. |----------------| |
  21. | H | |
  22. |----------------| |
  23.  
  24. |----------------| |
  25. | L | |
  26. |----------------| -/
  27.  
  28. |---------------------------------|
  29. | PC | - Program Counter
  30. |---------------------------------|
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. >>>Special Instructions:
  43.  
  44. OPC -> SUBC -> OPC -> NEXT INSTRUCTION
  45.  
  46. 0 - 0 \
  47. 1 - 0 /-----OP CODE
  48. 2 - 0 \
  49. 3 - 0 |
  50. 4 - 0 |
  51. 5 - 0 |-----CODE
  52. 6 - 0 |
  53. 7 - 0 /
  54.  
  55. CODE:
  56.  
  57. 000000 - NOP - NO OPCODE (does nothing, just goes to the next Address)
  58. 000001 - HALT - HALT (Stops the Program)
  59. 000010 - ???
  60. [...]
  61. 111111 - ???
  62.  
  63.  
  64.  
  65.  
  66.  
  67. >>>LD Instruction: (Moves data around)
  68.  
  69. OPC -> SOURCE -> OPC -> DESTINATION -> OPC -> NEXT INSTRUCTION
  70.  
  71. 0 - 1 \
  72. 1 - 0 /-----OP CODE
  73. 2 - 0 \
  74. 3 - 0 |-----SOURCE
  75. 4 - 0 /
  76. 5 - 0 \
  77. 6 - 0 |-----DESTINATION
  78. 7 - 0 /
  79.  
  80.  
  81. SOURCE/DESTINATION:
  82.  
  83. 000 - A
  84. 001 - B
  85. 010 - C
  86. 011 - H
  87. 100 - L
  88. 101 - MEM IMME loads/stores from/to the next byte
  89. 110 - MEM ADDR IMME loads the next 2 bytes as Address to load/store a value from/to
  90. 111 - MEM ADDR HL uses the contents of HL as Address to load/store a value from/to
  91.  
  92. Example: 01101000
  93.  
  94. OP code - 01 -> LD
  95. SOURCE - 101 -> MEM IMME
  96. DESTIN - 000 -> REG A
  97.  
  98. so in total this will move whatever is in the following Address into Register A
  99.  
  100.  
  101.  
  102. >>>AL Instruction: (does Math)
  103.  
  104. OPC -> SOURCE -> OPC -> ALI -> OPC -> DESTINATION -> OPC -> NEXT INSTRUCTION
  105.  
  106. 0 - 0 \
  107. 1 - 1 /-----OP CODE
  108. 2 - 0 \
  109. 3 - 0 |-----SOURCE/DESTINATION
  110. 4 - 0 /
  111. 5 - 0 \
  112. 6 - 0 |-----ALI
  113. 7 - 0 /
  114.  
  115. !WANRING! if SOURCE is a Memory location 2 Memory locations have to be specified, only exception is "MEM ADDR HL"
  116.  
  117. ALI:
  118.  
  119. 000 - ADD Add Source and A, storse result in Destination SOURCE + A -> DESTINATION
  120. 001 - SUB0 Subtract A from Source, stores result in Destination SOURCE - A -> DESTINATION
  121. 010 - SUB1 Subtract Source from A, stores result in Destination A - SOURCE -> DESTINATION
  122. 011 - AND ANDs the Source and A, stores result in Destination SOURCE AND A -> DESTINATION
  123. 100 - XOR XORs the Source and A, stores result in Destination SOURCE XOR A -> DESTINATION
  124. 101 - CMP Compare Source and A, nothing will be stored (except Flags) SOURCE . A -> NOT STORED
  125. 110 - INC Adds 1 to Source, store result in Destination SOURCE + 1 -> DESTINATION
  126. 111 - DEC Subtracts 1 from Source, store result in Destination SOURCE - 1 -> DESTINATION
  127.  
  128. Example: 10001000
  129.  
  130. OP code - 10 -> AL
  131. SOURCE - 001 -> REG B
  132. DESTIN - 000 -> ADD
  133.  
  134. so in total this will Add Register B and A and store the results in Register B
  135.  
  136.  
  137.  
  138. >>>JUMP Instruction: (moves execution to a specific address)
  139.  
  140. OPC -> A-SOURCE -> OPC -> JMP -> OPC -> NEXT INSTRUCTION
  141.  
  142. 0 - 1 \
  143. 1 - 1 /-----OP CODE
  144. 2 - 0 \
  145. 3 - 0 |-----A-SOURCE
  146. 4 - 0 /
  147. 5 - 0 |-----CONDITIONAL JUMP: NO/YES - 0/1
  148. 6 - X \
  149. 7 - X /-----???
  150.  
  151. FLAGS (Optional):
  152.  
  153. 0 - 0 |-----Zero Flag
  154. 1 - 0 |-----Overflow Flag
  155. 2 - 0 |-----Negative Flag
  156. 3 - 0 |-----Greater than Flag 1 if A > SOURCE
  157. 4 - 0 |-----Equal to Flag 1 if A = SOURCE
  158. 5 - 0 |-----Less than Flag 1 if A < SOURCE
  159. 6 - 0 |-----???
  160. 7 - 0 |-----???
  161.  
  162. !WARNING! Position of the FLAGS byte depends on the SOURCE used (example: if SOURCE is MEM IMME the 2 bytes after the Instruction would be the address, then the following byte would be the FLAGS)
  163.  
  164.  
  165. A-SOURCE:
  166.  
  167. 000 - HL uses the contents of HL as value
  168. 001 - MEM ADDR HL uses the contents of HL as Address to load a value from
  169. 010 - MEM IMME loads the next 2 byte as value
  170. 011 - ???
  171. 100 - ???
  172. 101 - ???
  173. 110 - ???
  174. 111 - ???
  175.  
  176.  
  177. Example: 10100000
  178.  
  179. OP code - 11 -> JMP
  180. SOURCE - 010 -> MEM IMME
  181.  
  182. so in total this will laod the next 2 bytes from Memory and load them into the PC
  183.  
  184.  
  185.  
  186. >>>>SPECIAL EXPLAINATIONS
  187.  
  188. Registers and such:
  189.  
  190. A, B, C, D, H, L -> Registers, can hold a single 8 bit Number
  191. PC -> Program Counter (16 bit), points to the currently executed Instruction/Data
  192. HL -> Combined values of H and L (16 bit). L being the lower byte and H being the higher byte. so if L would have the number "10010011" stored and H had "00001111". HL would have "00001111-10010011"
  193.  
  194. Memory usage for LD, ALU, JMP Instructions:
  195.  
  196. <???> <-- equals 1 byte in Memory
  197.  
  198. using Registers as source does not require additional Memory to be used.
  199.  
  200.  
  201. MEM IMME (loads the next byte as data from Memory)
  202.  
  203. <LD Instruction> <DATA>
  204.  
  205. <ALU Instruction> <DATA IN> <DATA OUT>
  206.  
  207. <JMP Instruction> <High byte of Address> <Low byte of Address> (JMP loads 2 bytes as it requires a 16 bit Number)
  208.  
  209.  
  210. MEM ADDR IMME (uses the next 2 bytes as Address to take a value from)
  211.  
  212. <Instruction> <High byte of Address> <Low byte of Address>
  213.  
  214. <ALU Instruction> <High byte of Address> <Low byte of Address> <High byte of Address> <Low byte of Address>
  215.  
  216.  
  217. Just remember:
  218.  
  219. Source always comes first then the Destination.
  220.  
  221. example: if you Load from MEM IMME to MEM ADDR IMME you first need to put the byte you want to load, then the next 2 bytes are the address you want to put that data to.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement