Lite / Engineering Complex Systems / 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?
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.
Predict
During the fetch step, which transfer happens?
- A ← A + M[a]
- IR ← ROM[PC]
- M[a] ← A
- PC ← a
Guess first, then reveal
Fetch copies the instruction the program counter points at into the instruction register. Only then can the control unit look at its opcode and decide what the execute step does.
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?
What the interactive shows (text version)
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.
Watch (optional)
Watch for: 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.
“8-bit CPU control logic: Part 1” by Ben Eater (opens YouTube; streaming video uses a lot of data)
The video is optional. Everything you need is in this lesson's text.
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
Intuitive
The datapath is an orchestra; the control unit is the conductor reading a score, telling each section exactly when to play.
Technical
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.
Mathematical
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.
Applied
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.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
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.
Reflect
Why might a designer choose microcode even though it is slower?
Write your answer on paper or in your own notes. Lite never stores what you write.