TactivergeLite

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?

About 35 min · 3 goals · Checked by automated tests · Full interactive version

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.

Predict

During the fetch step, which transfer happens?

  1. A ← A + M[a]
  2. IR ← ROM[PC]
  3. M[a] ← A
  4. 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.

You can also open the interactive on the full site when you have a faster connection.

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

Practice

Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.

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?

bits

Practice 5. During JNZ's execute step with Z = 1, what happens?

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.

← Thinking in register transfersHow fast can the clock tick? →