The Processor: Datapath & Control

the control unit

If the datapath is a factory floor of machines and conveyor belts, the control unit is the foreman who reads each work order and throws the right switches: turn on this machine, route the belt that way, hold that valve shut. The control unit is the part of the CPU that looks at the current instruction and produces the control signals that steer the datapath so the right thing happens for that particular instruction.

Mechanically, the control unit takes the opcode (and a few related bits) of the fetched instruction as input and outputs a bundle of control signals: RegWrite (should a register be written?), MemRead and MemWrite (touch data memory?), ALUSrc (does the ALU's second input come from a register or an immediate?), MemToReg (does write-back data come from the ALU or from memory?), Branch (is this a branch?), and an ALU-operation hint that the small ALU control turns into the exact ALU function. For a single-cycle CPU this is pure combinational logic: opcode in, signal bundle out, with no memory of past instructions.

The deep point is the seam this creates. Because the control unit is separate from the datapath, you can change WHAT the machine does (the control) without rewiring HOW data flows (the datapath), and vice versa. Hardwired control implements this logic as fixed gates; microprogrammed control stores the signal patterns in a tiny internal memory. Either way, the control unit is where the meaning of an instruction (its opcode) gets translated into physical action.

Fed the opcode of a load, the control unit outputs ALUSrc = 1 (use the immediate), MemRead = 1, MemToReg = 1 (write back from memory), RegWrite = 1, and Branch = 0. Fed an R-type opcode it instead outputs ALUSrc = 0, MemRead = 0, MemToReg = 0, RegWrite = 1, Branch = 0.

Opcode in, control signals out: the control unit translates an instruction into switch settings for the datapath.

The control unit doesn't move data; it only sets switches. People sometimes imagine 'the controller runs the program', but it just decodes each instruction into signals — the datapath does the actual moving and computing.

Also called
controller控制器