School/□ Systems Engineer/Week 26
The control unit is a state machine
A processor's datapath can add, store and jump, but it does nothing on its own. What tells each part when to act?
About 35 min · 3 goals · Checked by automated tests
1.Why should I care?
This is where state machines, register transfers and instruction sets meet. Once you see the control unit as an FSM driving control signals, a processor stops being a black box and becomes something you could design.
- ◇ Describe fetch, decode and execute as register transfers.
- ◇ List the control signals asserted in each step of an instruction.
- ◇ Explain microcode as a table of control signals stored in memory.
2.Predict
During the fetch step, which transfer happens?
Guess first. Being wrong here is how the surprise works.
3.Discover
Load 'Double twice' and click one cycle at a time. For each cycle write the RTL line and the control signals shown. Which signals appear in every instruction, and which only for ADD?
Loading the interactive…
Can't use the interactive? Read a description instead
Stepping 'Double twice', every instruction starts with fetch (rom_read, ir_load: IR ← ROM[PC]) and decode (pc_inc: PC ← PC + 1). Execute differs: LOAD asserts ram_read, alu_pass, a_load, flags_load; ADD asserts ram_read, alu_add, a_load, flags_load; STORE asserts ram_write; HALT asserts halt.
4.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1
In the stepper's model, what does the decode step change?
Practice 2
Which control signal is asserted for every instruction in the model?
5.Watch
→ Watch for the table of steps and which control lines are on in each step: it is the same table you are building from the stepper.
On a real breadboard computer, works out which control signals must be on during each step of fetch and execute: register-transfer design you can touch.
Length: see YouTube · captions on YouTube · source
Nothing loads from YouTube until you press play.
The video is optional: everything you need is also in the lesson text and the interactive.
6.Understand
Fetch, decode, execute as RTL
In the stepper's model each instruction takes three cycles. Fetch: IR ← ROM[PC]. Decode: PC ← PC + 1 while the control unit reads the opcode. Execute: the opcode's own transfer, such as A ← A + M[a] with flags updated, or if Z = 0: PC ← a. Then back to fetch.
Control signals
Each transfer happens because control lines are on: rom_read and ir_load in fetch; pc_inc in decode; for ADD, ram_read, alu_add, a_load and flags_load. The control unit is an FSM whose state is the step (fetch, decode, execute) and whose outputs, depending on that state and the opcode, are these signals.
Hard-wired or microcoded
A hard-wired control unit computes the signals with gates. A microcoded one stores them in a small memory addressed by (opcode, step): each row is one cycle's control word. Microcode is easier to change and fix; hard-wired is faster. Ben Eater's breadboard computer uses EEPROMs as microcode.
Explain it another way
The datapath is an orchestra; the control unit is the conductor reading a score, telling each section exactly when to play.
Pipelined processors overlap fetch, decode and execute of different instructions, so the control unit must also handle hazards: a jump makes the already-fetched next instruction wrong.
Microcode ROM size = (number of opcodes) × (steps per instruction) × (control-word width). Nibble with 16 opcodes, 3 steps and 8 signals: 16 × 3 = 48 words of 8 bits.
Modern x86 processors still contain microcode for complex instructions, and vendors ship microcode updates to fix bugs found after chips are manufactured.
Worked example 1
List the control signals for STORE 4 in each of its three cycles.
Fetch: rom_read, ir_load. Decode: pc_inc. Execute: ram_write (with address 4 from the IR's operand field). Flags are not loaded.
Common mix-ups
- The program counter is incremented after the instruction finishes.
✓ In many designs, including this model, it is incremented early (during decode) and a jump overwrites it later.
7.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 3
A microcoded machine has 16 opcodes, 4 steps per instruction and a 12-bit control word. How many bits of microcode ROM?
Practice 4 · a fresh version every time
An 8-bit register R starts at 238. Each clock edge performs R ← (R + 25) mod 256. What does R hold after 4 cycles?
Practice 5
During JNZ's execute step with Z = 1, what happens?
8.Apply it
Write the full control table (opcode × step → signals) for the five Nibble instructions. Then add a new instruction of your choice and the rows it needs.
9.Reflect
Concepts: Register-transfer-level design · Super-loops and finite state machines · Instruction set architecture