Theory: Control Signals, Timing & the Control Unit
In 6.3 we wrote each instruction as a sequence of RTL microoperations such as MAR ← X. But hardware does not read RTL. Each microoperation happens because the control unit raises a particular set of control signals (wires set to 1) during a particular clock cycle. This lesson shows how to turn RTL into control signals, how to draw the timing diagram, and the two ways of building a control unit: hardwired and microprogrammed.
MARIE’s Control Signals
Careful inspection of MARIE’s RTL shows the ALU only ever needs three operations (add, subtract, clear) plus a fourth “do nothing” state. Together with the bus and the clock, the complete set of control signals is:
Signals
Purpose
P2P1P0
read: the 3-bit number of the register whose contents are put onto the bus (source)
P5P4P3
write: the 3-bit number of the register that loads from the bus (destination)
timing: exactly one is 1 in each clock cycle (from a counter)
Cr
counter reset: sends the timing counter back to T0 (the instruction is finished)
MR
memory read enable
MW
memory write enable
LALT
load the AC from the ALU through the dedicated AC/MBR/ALU path (not the bus)
The register numbers are the bus device numbers from 6.2:
Device
Memory
MAR
PC
MBR
AC
InREG
OutREG
IR
Number
0
1
2
3
4
5
6
7
Binary
000
001
010
011
100
101
110
111
A signal appears in a signal list only when it is 1. For example, “write the MBR” means P5P4P3=011, so we list P4P3 (and not P5).
Each register has a read (data out) enable and a write (data in) enable. The P lines go through decoders: the 3-bit read code turns on exactly one register’s output onto the bus, the 3-bit write code turns on exactly one register’s load input. In the same cycle one register sends and one register receives.
Deriving the Signal Sequence for an Instruction
Write the instruction’s RTL (skip fetch/decode, which use T0–T2; execution starts at T3).
Give each microoperation its own clock cycle: T3,T4,T5,…
For each step Dest ← Source:
put the source register’s number on P2P1P0 (list the bits that are 1);
put the destination register’s number on P5P4P3;
if the source is memory (M[MAR]), add MR (memory is device 000, so no P bits);
if the destination is memory, add MW;
if the step is an ALU operation into the AC, add the A1A0 code and LALT (plus P5 to enable writing the AC).
Add the timing signal Tn, and add Cr to the last step.
Mini-example (as in the lecture): Add X
RTL
Source → read bits
Destination → write bits
Extra
Signals
MAR ← X
IR (X = IR[11–0]) = 111 → P2P1P0
MAR = 001 → P3
P3P2P1P0T3
MBR ← M[MAR]
memory = 000
MBR = 011 → P4P3
MR
P4P3T4MR
AC ← AC + MBR
ALU (dedicated path)
AC = 100 → P5
A1A0=01→A0, LALT, last → Cr
CrA0P5T5LALT
P3 P2 P1 P0 T3 : MAR <- XP4 P3 T4 MR : MBR <- M[MAR]Cr A0 P5 T5 LALT : AC <- AC + MBR [reset counter]
These signals are ANDed together by combinational logic to produce the machine’s behaviour.
Timing Diagrams
A timing diagram draws each control signal as a waveform over the clock cycles. A signal is high in exactly those cycles whose signal list contains it. The Add instruction (cycles C3–C5):
Build the diagram row by row from the signal lists: for P3 ask “is P3 in the T3 list? in the T4 list? in the T5 list?” and draw high/low accordingly. P3 is high in both C3 and C4 because both MAR and MBR are written (001 and 011 both have bit 0 set).
Implementing the Control Unit
The control unit keeps things synchronized, making sure the right bits flow to the right components at the right time. There are two general implementations.
Hardwired control
The control logic is built directly from digital logic:
The opcode bits IR[15–12] feed an instruction decoder (4 inputs → one AND gate per instruction). The Add gate, for opcode 0011, is
Add=IR15′IR14′IR13IR12.
A ring counter clocked by the system clock produces the timing signals: exactly one of T0,T1,T2,… is high in each cycle, moving one place per clock tick. Cr resets it to T0.
Every control signal is an OR of ANDs of (instruction line) · (timing line). For Add alone:
Add⋅T3 drives P0,P1,P2,P3;
Add⋅T4 drives P3,P4,MR;
Add⋅T5 drives P5,A0,Cr,LALT.
So, for instance, P3=Add⋅T3+Add⋅T4+(terms from other instructions).
Diagram loads as you scroll.
Microprogrammed control
Instead of wiring the logic, store it as a program: each machine instruction is carried out by a short sequence of microinstructions (its microcode), kept in a fast ROM called the control store (this firmware is the microprogram).
A microinstruction address generator (using the IR and status flags) selects a microinstruction.
The microinstruction is fetched from the control store into a microinstruction buffer, decoded, and its control signals are sent to the datapath.
One microinstruction is retrieved during each clock cycle.
A microprogrammed control unit works like a computer in miniature: microinstructions are fetched, decoded and executed just like ordinary instructions.
MicroOp1, MicroOp2: two microoperation codes (5 bits each) carried out in the same cycle (NOP = 00000 if unused).
Jump: if 1, the Dest field must be a valid microprogram address for the control to branch to.
Dest: 7-bit address. MARIE’s microprogram has fewer than 128 lines, so 27=128 addresses suffice.
Microoperation codes (Table 4.9)
Code
Microoperation
Code
Microoperation
00000
NOP
01101
MBR ← M[MAR]
00001
AC ← 0
01110
OutREG ← AC
00010
AC ← MBR
01111
PC ← IR[11–0]
00011
AC ← AC − MBR
10000
PC ← MBR
00100
AC ← AC + MBR
10001
PC ← PC + 1
00101
AC ← InREG
10010
If AC = 00
00110
IR ← M[MAR]
10011
If AC > 0
00111
M[MAR] ← MBR
10100
If AC < 0
01000
MAR ← IR[11–0]
10101
If IR[11–10] = 00
01001
MAR ← MBR
10110
If IR[11–10] = 01
01010
MAR ← PC
10111
If IR[11–10] = 10
01011
MAR ← X
11000
If IR[15–12] = MicroOp2[4–1]
01100
MBR ← AC
The start of MARIE’s microprogram (Fig. 4.23)
Address
MicroOp1
MicroOp2
Jump
Dest
0000000
MAR ← PC
NOP
0
0000000
0000001
IR ← M[MAR]
NOP
0
0000000
0000010
PC ← PC + 1
NOP
0
0000000
0000011
MAR ← IR[11–0]
NOP
0
0000000
0000100
If IR[15–12] = MicroOp2[4–1]
00000
1
0100000
0000101
If IR[15–12] = MicroOp2[4–1]
00010
1
0100111
0000110
If IR[15–12] = MicroOp2[4–1]
00100
1
0101010
0000111
If IR[15–12] = MicroOp2[4–1]
00110
1
0101100
0001000
If IR[15–12] = MicroOp2[4–1]
01000
1
0101111
…
…
…
…
…
Lines 0–3 are the fetch–decode cycle (one microoperation per line, Jump = 0 so control just falls through to the next line).
Lines 4 onward form a jump table: each line compares the opcode IR[15–12] with bits 4–1 of MicroOp2 (00000 → 0000 JnS, 00010 → 0001 Load, 00100 → 0010 Store, 00110 → 0011 Add, 01000 → 0100 Subt). On a match it jumps to the routine for that instruction: JnS at 0100000 (32), Load at 0100111 (39), Store at 0101010 (42), Add at 0101100 (44), Subt at 0101111 (47).
Each instruction’s routine ends with Jump = 1, Dest = 0000000, which returns to line 0 to fetch the next instruction.
Mini-example
The routines for Store and Add (continuing Fig. 4.23):
Address
MicroOp1
MicroOp2
Jump
Dest
0101010 (Store)
MAR ← X
MBR ← AC
0
0000000
0101011
M[MAR] ← MBR
NOP
1
0000000
0101100 (Add)
MAR ← X
NOP
0
0000000
0101101
MBR ← M[MAR]
NOP
0
0000000
0101110
AC ← AC + MBR
NOP
1
0000000
Store uses both MicroOp fields in its first line, doing two microoperations in one cycle.
Hardwired vs Microprogrammed
Hardwired
Microprogrammed
Implementation
decoder + ring counter + AND/OR gates
microprogram (firmware) in a control store
Speed
fast: signals come straight from logic
slower: an extra level of interpretation (each microinstruction must itself be fetched and decoded)
Changing the instruction set / fixing a bug
redesign the circuit
just rewrite the microprogram
Complex instructions
hard: logic grows very large
easy: just a longer microroutine
Typical use
RISC processors, simple fast designs
CISC processors with large, complex instruction sets
How Many Instructions? RISC vs CISC
The number of instructions an ISA supports is a fundamental design trade-off.
Few instructions (RISC style)
Many instructions (CISC style)
Simple, small decoder; easy to hardwire → faster clock
Variable-length, complex instructions are harder to pipeline
Short opcode (4 bits → 16 instructions) leaves more bits for addresses/registers
509 instructions need ⌈log2509⌉=9 opcode bits
Compilers mostly use a small subset of instructions anyway
Each instruction does more → fewer instructions per program, denser code, fewer memory fetches
Easier to design, verify and test
High-level operations in hardware; backward compatibility with older code
Mini-example
With 16-bit instructions: 15 instructions need a 4-bit opcode, leaving 12 address bits (212=4K words). 509 instructions need a 9-bit opcode, leaving only 7 address bits (27=128 words): the instructions would have to grow or rely on registers.
Worked Examples
Exercise 1
Derive the control-signal sequence for MARIE’s Subt X instruction (execution phase only, starting at T3) and draw its timing diagram.
Show solution ↓Hide solution ↑
Solution
RTL: MAR ← X; MBR ← M[MAR]; AC ← AC − MBR.
Step
RTL
Read (source)
Write (dest)
Extra
Signals
T3
MAR ← X
IR 111 → P2P1P0
MAR 001 → P3
P3P2P1P0T3
T4
MBR ← M[MAR]
memory 000
MBR 011 → P4P3
MR
P4P3T4MR
T5
AC ← AC − MBR
ALU
AC 100 → P5
A1A0=10→A1; LALT; Cr
CrA1P5T5LALT
The only difference from Add is A1 (subtract, 10) instead of A0 (add, 01).
Exercise 2
Derive the control signals for Store X. Its RTL is MAR ← X, MBR ← AC; M[MAR] ← MBR. Note that MARIE has a single bus.
Show solution ↓Hide solution ↑
Solution
MAR ← X and MBR ← AC both need the bus (IR → MAR and AC → MBR), and the single bus can carry only one value per cycle, so they take separate cycles:
Hardwired control. Using the instruction decoder and timing signals:
(a) Write the Boolean expression for the decoder output Load (opcode 0001) and Add (opcode 0011).
(b) Considering only the Load instruction (P3P2P1P0T3; P4P3T4MR; P5P1P0T5Cr) and the Add instruction, write the Boolean expressions for P0, P3, P5, MR and Cr.
Show solution ↓Hide solution ↑
Solution
(a) A decoder output is the AND of the opcode bits, complemented where the bit is 0 (IR15 is the leftmost):
(b) Collect, for each signal, every (instruction, time) pair in which it appears and OR them:
Signal
Load appears at
Add appears at
Expression
P0
T3, T5
T3
LoadT3+LoadT5+AddT3
P3
T3, T4
T3, T4
(Load+Add)(T3+T4)
P5
T5
T5
(Load+Add)T5
MR
T4
T4
(Load+Add)T4
Cr
T5
T5
(Load+Add)T5
Note Load+Add=IR15′IR14′IR12(IR13′+IR13)=IR15′IR14′IR12, so e.g. MR=IR15′IR14′IR12T4 for these two instructions.
Exercise 5
Microcode. Using Table 4.9, write the binary microcode for the Store and Add routines that start at 0101010 and 0101100 (see the mini-example above). Then give each line as a single 18-bit word.
Show solution ↓Hide solution ↑
Solution
Look up each microoperation: MAR ← X = 01011, MBR ← AC = 01100, M[MAR] ← MBR = 00111, MBR ← M[MAR] = 01101, AC ← AC + MBR = 00100, NOP = 00000.
Address
MicroOp1
MicroOp2
Jump
Dest
18-bit word
0101010
01011
01100
0
0000000
01011 01100 0 0000000
0101011
00111
00000
1
0000000
00111 00000 1 0000000
0101100
01011
00000
0
0000000
01011 00000 0 0000000
0101101
01101
00000
0
0000000
01101 00000 0 0000000
0101110
00100
00000
1
0000000
00100 00000 1 0000000
Check the length: 5+5+1+7=18 bits ✓. The last line of each routine has Jump = 1 and Dest = 0000000: return to line 0 (fetch).
Exercise 6
Decode these MARIE microinstructions (18 bits, written MicroOp1 | MicroOp2 | Jump | Dest):
What does (a) do when the IR holds 3105? When it holds 1104?
Show solution ↓Hide solution ↑
Solution
(a) MicroOp1 = 11000 → “If IR[15–12] = MicroOp2[4–1]”. MicroOp2 = 00110 → bits 4–1 = 0011 (Add). Jump = 1, Dest = 01011002=44. Meaning: if the opcode is Add, jump to microprogram line 44 (the Add routine). This is line 0000111 of Fig. 4.23.
IR = 3105: opcode 0011 = 0011 → jump to 0101100.
IR = 1104: opcode 0001 ≠ 0011 → no jump; control continues to the next line of the jump table.
(b) 01010 = MAR ← PC, MicroOp2 NOP, no jump: the first fetch step (line 0).
(c) 10001 = PC ← PC + 1, NOP, no jump: the third fetch step (line 2).
Exercise 7
(a) MARIE’s control store holds up to 128 microinstructions. How many bits of ROM is that?
(b) Why is the Dest field 7 bits?
(c) Give two reasons a microprogrammed control unit is slower than a hardwired one, and two advantages that make it worth using.
Show solution ↓Hide solution ↑
Solution
(a)128×18=2304 bits.
(b) It must be able to name any of the ≤128=27 microprogram lines, so it needs log2128=7 bits.
(c) Slower because (1) every microinstruction must itself be fetched from the control store and decoded before its signals appear: an extra level of interpretation; (2) a machine instruction takes several microinstructions (several control-store accesses), including the jump-table lookups.
Advantages: (1) flexibility: changing the instruction set or fixing a design error only requires changing the microprogram, not the hardware; (2) it can support very complicated instructions easily (just longer microroutines).