Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>>>Data Structure:
- Registers:
- 0 7 15
- | | |
- |----------------| -\
- | A | |
- |----------------| |
- |----------------| |
- | B | |
- |----------------| |
- |----------------| \
- | C | - General Purpose Registers
- |----------------| /
- |----------------| |
- | H | |
- |----------------| |
- |----------------| |
- | L | |
- |----------------| -/
- |---------------------------------|
- | PC | - Program Counter
- |---------------------------------|
- >>>Special Instructions:
- OPC -> SUBC -> OPC -> NEXT INSTRUCTION
- 0 - 0 \
- 1 - 0 /-----OP CODE
- 2 - 0 \
- 3 - 0 |
- 4 - 0 |
- 5 - 0 |-----CODE
- 6 - 0 |
- 7 - 0 /
- CODE:
- 000000 - NOP - NO OPCODE (does nothing, just goes to the next Address)
- 000001 - HALT - HALT (Stops the Program)
- 000010 - ???
- [...]
- 111111 - ???
- >>>LD Instruction: (Moves data around)
- OPC -> SOURCE -> OPC -> DESTINATION -> OPC -> NEXT INSTRUCTION
- 0 - 1 \
- 1 - 0 /-----OP CODE
- 2 - 0 \
- 3 - 0 |-----SOURCE
- 4 - 0 /
- 5 - 0 \
- 6 - 0 |-----DESTINATION
- 7 - 0 /
- SOURCE/DESTINATION:
- 000 - A
- 001 - B
- 010 - C
- 011 - H
- 100 - L
- 101 - MEM IMME loads/stores from/to the next byte
- 110 - MEM ADDR IMME loads the next 2 bytes as Address to load/store a value from/to
- 111 - MEM ADDR HL uses the contents of HL as Address to load/store a value from/to
- Example: 01101000
- OP code - 01 -> LD
- SOURCE - 101 -> MEM IMME
- DESTIN - 000 -> REG A
- so in total this will move whatever is in the following Address into Register A
- >>>AL Instruction: (does Math)
- OPC -> SOURCE -> OPC -> ALI -> OPC -> DESTINATION -> OPC -> NEXT INSTRUCTION
- 0 - 0 \
- 1 - 1 /-----OP CODE
- 2 - 0 \
- 3 - 0 |-----SOURCE/DESTINATION
- 4 - 0 /
- 5 - 0 \
- 6 - 0 |-----ALI
- 7 - 0 /
- !WANRING! if SOURCE is a Memory location 2 Memory locations have to be specified, only exception is "MEM ADDR HL"
- ALI:
- 000 - ADD Add Source and A, storse result in Destination SOURCE + A -> DESTINATION
- 001 - SUB0 Subtract A from Source, stores result in Destination SOURCE - A -> DESTINATION
- 010 - SUB1 Subtract Source from A, stores result in Destination A - SOURCE -> DESTINATION
- 011 - AND ANDs the Source and A, stores result in Destination SOURCE AND A -> DESTINATION
- 100 - XOR XORs the Source and A, stores result in Destination SOURCE XOR A -> DESTINATION
- 101 - CMP Compare Source and A, nothing will be stored (except Flags) SOURCE . A -> NOT STORED
- 110 - INC Adds 1 to Source, store result in Destination SOURCE + 1 -> DESTINATION
- 111 - DEC Subtracts 1 from Source, store result in Destination SOURCE - 1 -> DESTINATION
- Example: 10001000
- OP code - 10 -> AL
- SOURCE - 001 -> REG B
- DESTIN - 000 -> ADD
- so in total this will Add Register B and A and store the results in Register B
- >>>JUMP Instruction: (moves execution to a specific address)
- OPC -> A-SOURCE -> OPC -> JMP -> OPC -> NEXT INSTRUCTION
- 0 - 1 \
- 1 - 1 /-----OP CODE
- 2 - 0 \
- 3 - 0 |-----A-SOURCE
- 4 - 0 /
- 5 - 0 |-----CONDITIONAL JUMP: NO/YES - 0/1
- 6 - X \
- 7 - X /-----???
- FLAGS (Optional):
- 0 - 0 |-----Zero Flag
- 1 - 0 |-----Overflow Flag
- 2 - 0 |-----Negative Flag
- 3 - 0 |-----Greater than Flag 1 if A > SOURCE
- 4 - 0 |-----Equal to Flag 1 if A = SOURCE
- 5 - 0 |-----Less than Flag 1 if A < SOURCE
- 6 - 0 |-----???
- 7 - 0 |-----???
- !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)
- A-SOURCE:
- 000 - HL uses the contents of HL as value
- 001 - MEM ADDR HL uses the contents of HL as Address to load a value from
- 010 - MEM IMME loads the next 2 byte as value
- 011 - ???
- 100 - ???
- 101 - ???
- 110 - ???
- 111 - ???
- Example: 10100000
- OP code - 11 -> JMP
- SOURCE - 010 -> MEM IMME
- so in total this will laod the next 2 bytes from Memory and load them into the PC
- >>>>SPECIAL EXPLAINATIONS
- Registers and such:
- A, B, C, D, H, L -> Registers, can hold a single 8 bit Number
- PC -> Program Counter (16 bit), points to the currently executed Instruction/Data
- 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"
- Memory usage for LD, ALU, JMP Instructions:
- <???> <-- equals 1 byte in Memory
- using Registers as source does not require additional Memory to be used.
- MEM IMME (loads the next byte as data from Memory)
- <LD Instruction> <DATA>
- <ALU Instruction> <DATA IN> <DATA OUT>
- <JMP Instruction> <High byte of Address> <Low byte of Address> (JMP loads 2 bytes as it requires a 16 bit Number)
- MEM ADDR IMME (uses the next 2 bytes as Address to take a value from)
- <Instruction> <High byte of Address> <Low byte of Address>
- <ALU Instruction> <High byte of Address> <Low byte of Address> <High byte of Address> <Low byte of Address>
- Just remember:
- Source always comes first then the Destination.
- 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