Bits that mean do this
12Instruction decoding
- Stage 1
- Stage 2
- Stage 3
- Stage 4
- Stage 5
- Stage 6
- Stage 7
- Stage 8
- Stage 9
- Stage 10
- Stage 11
- Stage 12 (this one)
- Stage 13
- Stage 14
- Stage 15
Explanation
An instruction is just a number in memory. In Bench-8 every instruction is two bytes: the top four bits of the first byte are the opcode (16 possible instructions) and the second byte is the operand, a number or an address.
The decoder turns the opcode into control signals: which register loads, what the ALU does, whether memory is read or written, whether the program counter jumps. Change the opcode and different wires light up.
Feed the decoder an instruction
Byte 1 = 0x40: opcode 4 (top four bits)
Byte 2 = operand 16
ADD 16
A ← A + M[16]. Add the byte at a to A (8-bit wraparound, C = carry out).
- ● ADDR←OPR
- ● MEM_RD
- ○ MEM_WR
- ● ALU_ADD
- ○ ALU_SUB
- ○ ALU_AND
- ○ ALU_OR
- ○ ALU_XOR
- ○ ALU_NOT
- ○ ALU_PASS
- ● A_LOAD
- ● FLAGS_LOAD
- ○ PC_LOAD
- ○ PC_LOAD_IF_Z
- ○ PC_LOAD_IF_C
- ○ IN_RD
- ○ OUT_WR
- ○ HALT
ADD: lines ADDR←OPR, MEM_RD, ALU_ADD, A_LOAD, FLAGS_LOAD
Check yourself
Marked instantly in your browser. Use the interactive above to work it out.