The Processor: Datapath & Control

executing an arithmetic instruction

Let's walk one of the simplest instructions through the datapath: an arithmetic operation like 'add x3, x1, x2' — read two registers, combine them, write the result to a third register. These are called R-type (register-type) instructions because all three operands are registers and nothing touches memory. Following this single instruction step by step is the best way to see the datapath come alive.

The trip has five clear steps. (1) Fetch: the PC addresses instruction memory, which returns the 32-bit instruction, and the PC is bumped to PC + 4 for next time. (2) Decode and read registers: the control unit looks at the opcode while the register file reads the two source registers (x1 and x2) named in the instruction fields, placing their values on the ALU's two inputs. (3) Execute: the ALU performs the requested operation (here, add) on those two values. (4) The result goes back toward the register file (a load would detour through data memory here, but R-type does not). (5) Write-back: with the RegWrite control signal asserted, the ALU result is written into the destination register (x3).

Notice what is OFF for an arithmetic instruction: MemRead and MemWrite are both 0 (memory is untouched), the branch signal is 0 (control falls through to PC + 4), and a mux is set so the ALU's second input comes from a register rather than a sign-extended immediate. The same physical wires that a load uses are present, but control simply doesn't switch them on. That is the whole idea of the datapath/control split in one example.

For 'sub x6, x4, x5': register file reads x4 and x5, the mux feeds x5 (not an immediate) into the ALU, the ALU subtracts, RegWrite is 1 so x6 gets the difference, MemRead = MemWrite = Branch = 0, and the PC advances to PC + 4.

An R-type instruction: read two registers, ALU combines them, write back — memory and branch stay off.

Every instruction type travels the SAME datapath; only the control signals differ. R-type just happens to leave the memory and branch paths switched off — the hardware for them is still physically there.

Also called
R-type executionregister-register instruction暫存器-暫存器指令執行