Instruction trace: ADD x3, x1, x2
Cycle-by-cycle walk-through (4 cycles total):
| Cycle |
State |
Key datapath action |
What updates |
| 1 |
FETCH |
IR ← mem[PC]; PC ← PC+4 via ALU |
IR, PC |
| 2 |
DECODE |
read rs1=x1, rs2=x2; decode R-type; state_next = EXEC_R |
(combinational) |
| 3 |
EXEC_R |
ALU computes x1 + x2; result → ALUOUT |
ALUOUT |
| 4 |
WRITEBACK_ALU |
x3 ← ALUOUT; state_next = FETCH |
register file |
Control signals in cycle 3: alu_src_a=RS1, alu_src_b=RS2, alu_op=ADD, reg_write=0 (not yet).
Control signals in cycle 4: reg_write=1, result_src=ALUOUT, reg_dst=rd.
Every R-type and I-type ALU instruction follows this exact 4-cycle template. The FSM reuses the same states — only the alu_op and the source of alu_src_b differ.