Datapath & Control Unit

How a single-cycle and multi-cycle processor wires registers, ALU and memory together, and how the control unit (hardwired or microprogrammed) drives them.

Advanced 3 min readLesson 8 of 15

The datapath is the hardware that moves and transforms data: the PC, instruction memory, register file, ALU, data memory and the multiplexers between them. The control unit looks at each instruction and sets the control signals that tell the datapath what to do. Together they implement the ISA.

A single-cycle datapath

Every instruction completes in one (long) clock cycle. Here's the path a RISC-V lw or add takes:

PCInstruction memoryRegister fileread rs1, rs2ALUData memoryControl unitfrom opcodewrite back → rd
Stageadd x1, x2, x3lw x1, 8(x2)sw x1, 8(x2)beq x1, x2, L
Fetch✓✓✓✓
Read registersx2, x3x2x1, x2x1, x2
ALUx2 + x3x2 + 8 (address)x2 + 8x1 − x2 (zero?)
Memory—readwrite—
Write backx1x1——
Next PCPC + 4PC + 4PC + 4PC + 4 or target

Control signals

The control unit decodes the opcode into signals such as:

SignalChooses
RegWriteWhether to write the register file
ALUSrcSecond ALU input: register or immediate
ALUOpWhich operation the ALU performs
MemRead / MemWriteWhether to read or write data memory
MemToRegWrite back the ALU result or the loaded value
BranchWhether the next PC may be the branch target

Each is a wire into a MUX or an enable input: the "if statements" of hardware.

Why not single-cycle?

The clock period must fit the slowest instruction (a load: fetch + register read + ALU + memory + write back), so fast instructions waste most of their cycle.

Multi-cycle

Break execution into steps of about one memory access or ALU operation each; an instruction takes 3–5 short cycles depending on its type. Hardware can be reused across steps (one ALU, one memory). CPI is above 1 but the clock is much faster.

Pipelined

Use the same steps, but start a new instruction every cycle, with each stage working on a different instruction. Ideal CPI = 1 with a fast clock. This is what real CPUs do — see Pipelining.

Hardwired vs microprogrammed control

Hardwired

Control signals come from combinational logic (an FSM). Fast, but hard to change. Used by RISC cores and for the common, simple instructions in all modern CPUs.

Microprogrammed

Each machine instruction runs a small microprogram stored in a control ROM; each microinstruction sets the control signals for one step. Flexible and easy to extend; slower. Classic for CISC. x86 still uses microcode for complex instructions and can patch it with microcode updates (used for Spectre fixes).

Exceptions and interrupts in the datapath

When something unusual happens — an illegal instruction, a page fault, a divide by zero, or an external interrupt — the control unit must:

  1. Stop the faulting instruction (and everything after it) from changing state.
  2. Save the PC of the faulting instruction (RISC-V mepc) and the cause (mcause).
  3. Switch to privileged mode and jump to the OS trap handler.
  4. After the handler finishes, return to the saved PC (re-executing the instruction after, say, a page fault).

Doing this precisely in a pipelined, out-of-order CPU is why the reorder buffer exists. See I/O & interrupts.

Key takeaways
  • Datapath = PC, instruction memory, register file, ALU, data memory and the MUXes between them.
  • The control unit decodes the opcode into control signals (RegWrite, ALUSrc, MemRead…).
  • Single-cycle is simple but the clock must fit the slowest instruction.
  • Multi-cycle reuses hardware; pipelining overlaps instructions for CPI ≈ 1.
  • Hardwired control is fast; microprogrammed control is flexible and patchable.