Sub topic 13
What the Control Unit Does
This chapter assumes that you know binary numbers, basic logic gates, registers, and memory. You should also recognize a processor as a datapath, which is the collection of registers, buses, and functional units that move and transform data.
The control unit as a coordinator
The control unit directs the datapath. It does not normally perform addition or store data itself. Instead, it reads the current instruction and sends control signals that select operations such as:
- Loading a register.
- Enabling a bus connection.
- Reading from or writing to memory.
- Selecting an ALU operation.
- Updating the program counter.
- Updating status flags.
A control signal is usually a one-bit command. For example, MemRead = 1 requests a memory read, while IRLoad = 1 tells the instruction register to capture the value on the data bus.
The control unit uses three main inputs:
- The instruction register, which contains the current instruction.
- Timing information, which identifies the current step of the instruction cycle.
- Status flags, such as zero, carry, or negative, for conditional instructions.
Its outputs are the control signals that cause register transfers and datapath operations.
Fetch, decode, and execute
Every instruction begins with a fetch sequence. A simple processor might perform these transfers:
| Time | Register transfer | Purpose |
|---|---|---|
| T0 | `MAR ← PC` | Copy the next instruction address to the memory address register |
| T1 | `MDR ← M[MAR]`, `PC ← PC + 1` | Read memory and advance the program counter |
| T2 | `IR ← MDR` | Place the instruction in the instruction register |
| T3 | Decode `IR` | Select the instruction's execute sequence |
Here, M[MAR] means the memory value at the address stored in MAR. The decoder examines the opcode and addressing-mode bits in IR. The control unit then chooses the required sequence of micro-operations.
Datapath actions during execution
Suppose an instruction adds register R2 to register R1 and stores the result in R1. The control unit can issue signals that cause this sequence:
- Select
R1as an ALU input. - Select
R2as the other ALU input. - Set the ALU operation to addition.
- Enable the destination register's load input.
- Update flags if the instruction requires it.
The same instruction therefore combines a decoded opcode with a series of timed control decisions. A wrong signal can select the wrong register, perform the wrong ALU operation, or overwrite valid data.
Exercise
Exercise
During fetch, why is the program counter usually incremented before the execute stage?
Show answer
It advances to the next instruction address while the current instruction is being fetched. A branch or other control-transfer instruction may later replace it with a different address.