Chapter 18 of 39

Hardwired Control Unit

An orchestra has many musicians, and each of them can play beautifully. But without a conductor, nobody knows when to start, when to stop, or who plays the next bar. The datapath we built in ALU & Datapath is the orchestra: registers, buses and an ALU that can do many things. What it lacks is a conductor that says, in every clock cycle, "PC out, MAR in, Read, now!". That conductor is the control unit.

There are two classic ways to build it. In this chapter we study the first one, where the control signals come straight out of logic gates. The second, where they are stored as words in a memory, is the topic of Microprogrammed Control Unit.

A hardwired control unit generates the control signals using fixed combinational logic (gates, decoders, PLAs) driven by a step counter, the decoded opcode of the current instruction, the condition flags and external signals. Its behaviour is fixed by the wiring; changing it means redesigning the circuit.

We will see the block diagram, derive the actual logic equations for several control signals from the control sequences of the previous chapter (derived with a small script so nothing is missed), look at Mano's basic computer, and compare the main design methods.


What the Control Unit Must Do

Recall the control sequence for ADD R1, (R3) on the single-bus datapath:

Step

Active control signals

T1

PCout, MARin, Read, Select4, Add, Zin

T2

Zout, PCin, Yin, WMFC

T3

MDRout, IRin

T4

R3out, MARin, Read

T5

R1out, Yin, WMFC

T6

MDRout, SelectY, Add, Zin

T7

Zout, R1in, End

So whether a control signal is 1 depends on exactly three kinds of information:

  1. Which step we are in (T1, T2, ...).

  2. Which instruction is being executed (the opcode in IR).

  3. Conditions: status flags such as N or Z, and external inputs such as MFC (memory function completed) or an interrupt request.

A hardwired control unit is simply a circuit that computes every control signal as a Boolean function of these inputs.


Block Diagram

          clock
            |
     +------v-------+        +--------------+
     | step counter |<-Reset-| End          |
     +------+-------+        +--------------+
            | (k bits)
     +------v-------+                 +-----------+
     | step decoder |                 |    IR     |
     +--+--+---+----+                 +-----+-----+
        |  |   |  T1 ... Tn                 | opcode
        v  v   v                     +------v-------+
     +-----------------------------+ | instruction  |
     |                             |<| decoder      | INS1 ... INSm
     |      encoder / control      | +--------------+
     |      logic (AND-OR gates)   |
     |                             |<-- condition codes (N, Z, C, V)
     |                             |<-- external inputs (MFC, interrupt)
     +--------------+--------------+
                    |
                    v
      control signals: PCout, MARin, Read, Add, Zin, ..., End, WMFC
  • The step counter advances by one on each clock. Its k-bit value is decoded into one-hot timing signals T1, T2, ..., Tn, exactly one of which is 1 at any time.

  • The instruction decoder turns the opcode into one-hot lines INS1 ... INSm (for example ADD, BR, BRN, LOAD), one per instruction.

  • The encoder combines these with the flags and external inputs using AND-OR logic and produces the control signals.

  • End resets the step counter to T1, so the next instruction fetch begins.

Waiting for Memory: the Run Signal

In step T2 the control unit must wait until memory has delivered the word (WMFC). The usual trick is a signal Run that enables the step counter:

Run = NOT (WMFC AND NOT MFC)
    = 1 normally; 0 while a WMFC step is waiting for MFC.

While Run = 0 the counter holds its value, so the same control signals stay active, and the step is stretched over as many clock cycles as memory needs. As soon as MFC arrives the counter moves on.


Deriving the Control Logic

To find the equation for one control signal, look at every control sequence and collect every step in which that signal is active. Each occurrence becomes one AND term (step AND instruction); the signal is the OR of all the terms.

Let us use four instructions on the single-bus datapath. Steps T1 to T3 are the common fetch.

Instruction

T4

T5

T6

T7

ADD R1, (R3) (memory add)

R3out, MARin, Read

R1out, Yin, WMFC

MDRout, SelectY, Add, Zin

Zout, R1in, End

ADD R1, R2 (register add)

R1out, Yin

R2out, SelectY, Add, Zin

Zout, R1in, End

-

LOAD R1, (R3)

R3out, MARin, Read

WMFC

MDRout, R1in, End

-

BR offset (branch)

Offsetout, SelectY, Add, Zin

Zout, PCin, End

-

-

For the branch, Y already holds the updated PC (it was loaded in T2), so T4 computes PC + offset. Call the decoded instruction lines ADDM, ADDR, LOAD and BR. Collecting the terms gives (· is AND, + is OR):

Zin     = T1 + T6·ADDM + T5·ADDR + T4·BR
Add     = T1 + T6·ADDM + T5·ADDR + T4·BR
Zout    = T2 + T7·ADDM + T6·ADDR + T5·BR
Yin     = T2 + T5·ADDM + T4·ADDR
PCin    = T2 + T5·BR
MARin   = T1 + T4·ADDM + T4·LOAD
Read    = T1 + T4·ADDM + T4·LOAD
WMFC    = T2 + T5·ADDM + T5·LOAD
MDRout  = T3 + T6·ADDM + T6·LOAD
R1in    = T7·ADDM + T6·ADDR + T6·LOAD
End     = T7·ADDM + T6·ADDR + T6·LOAD + T5·BR

Each equation is a two-level AND-OR circuit. For example, Zin is a 4-input OR gate whose inputs are T1 directly and three 2-input AND gates:

   T6 ----+
          AND ----+
 ADDM ----+       |
   T5 ----+       |
          AND ----+
 ADDR ----+       OR -----> Zin
   T4 ----+       |
          AND ----+
   BR ----+       |
   T1 ------------+

A real control unit has dozens of instructions, so each equation has many more terms, but the method is exactly the same. Fetch signals (T1 to T3) need no opcode term because they are the same for every instruction.

Notice that terms can be shared and simplified. MARin and Read happen to have identical equations here, so one AND-OR circuit can drive both. In real designs, logic minimisation (or a PLA) removes such duplication.

Adding a Conditional Branch

Now add BRN (branch if negative). Its sequence is:

T4: Offsetout, SelectY, Add, Zin, if N = 0 then End
T5: Zout, PCin, End

If the N flag is 0 the branch is not taken: End in T4 stops the instruction before PC is changed. If N = 1, T5 loads the target into PC. The new terms are:

Zin  = ... + T4·BRN
Add  = ... + T4·BRN
Zout = ... + T5·BRN
PCin = ... + T5·BRN
End  = T7·ADDM + T6·ADDR + T6·LOAD + T5·BR + T4·BRN·N' + T5·BRN

(Offsetout and SelectY gain the same T4·BRN term.) This is where the condition codes enter the control logic: a flag simply becomes one more input to an AND term. (T5·BRN needs no N term, because step T5 of BRN is reached only when N = 1.)


A Classic Example: Mano's Basic Computer

Mano's basic computer (a 16-bit accumulator machine, see CPU Organization: Accumulator, General Register & Stack) uses the same structure:

  • A 4-bit sequence counter SC and a 4 × 16 decoder producing timing signals T0 to T15.

  • A 3 × 8 decoder on the opcode bits IR(12-14) producing D0 to D7.

  • A flip-flop I holding the addressing-mode bit IR(15) (direct or indirect).

Its fetch and decode phase is:

T0:  AR ← PC
T1:  IR ← M[AR],  PC ← PC + 1
T2:  D0..D7 ← decode IR(12-14),  AR ← IR(0-11),  I ← IR(15)
T3:  if D7' and I:  AR ← M[AR]     (indirect address)

Reading off when AR is loaded gives the control function for its load input:

LD(AR) = T0 + T2 + D7'·I·T3

(In the full design with interrupts, the fetch terms are also ANDed with R', the complement of the interrupt flip-flop, giving LD(AR) = R'T0 + R'T2 + D7'IT3.) Every other register control input, such as INR(PC) or CLR(SC), is obtained the same way: list every micro-operation that uses it and OR their conditions.


Design Methods

There are three traditional ways to organise the sequencing part of a hardwired controller:

Method

Idea

Pros

Cons

State-table (FSM) method

Treat the control unit as a finite-state machine; derive next-state and output logic from a state table, with binary-encoded states.

Fewest flip-flops (⌈log2 S⌉ for S states)

Hard to design and modify for large instruction sets

Delay-element / one-hot method

One flip-flop (or delay element) per state; a "token" moves from one to the next.

Very direct translation of the flowchart; simple next-state logic

Needs S flip-flops

Sequence-counter method

A counter plus decoder produces T1, T2, ...; opcode and flags gate the outputs (the method used above).

Regular and easy to understand

Every instruction is stepped through the same counter

For a multi-cycle processor the control unit is usually described as a finite-state machine: states such as "instruction fetch", "decode/register fetch", "memory address computation", "memory access", "write back". The FSM's output logic produces the control signals in each state (a Moore machine), and its next-state logic uses the opcode and flags. The two-level logic can be built from random gates, a PLA or a ROM.


Advantages and Disadvantages

  • Fast: signals are produced by a few gate delays; there is no control memory to read every cycle.

  • Efficient for simple, regular instruction sets, so it is the natural choice for RISC processors and for pipelined designs.

  • Inflexible: fixing a bug or adding an instruction means changing the circuit (and the chip).

  • Complex for large instruction sets: hundreds of instructions with many addressing modes give huge, irregular logic that is hard to design and verify.

Modern x86 processors use both styles: simple, common instructions are decoded directly by hardwired logic into micro-operations, while rare, complex instructions are expanded by a microcode ROM. A brief preview comparison (details in the next chapter):

Aspect

Hardwired

Microprogrammed

Signals generated by

Logic gates, decoders, PLA

Control words stored in control memory

Speed

Faster

Slower (memory read per step)

Changes

Need redesign

Edit the microprogram

Typical use

RISC, pipelined CPUs

CISC, complex instructions


Solved Problems

Problem 1: Size of the Step Counter

The longest instruction of a CPU needs 13 control steps (including fetch). How big is the step counter and the step decoder?

Solution. We need at least 13 distinct counter values. 23 = 8 is too few and 24 = 16 is enough, so a 4-bit counter and a 4-to-16 decoder (only T1 to T13 used).

Problem 2: Instruction Decoder Size

A CPU has a 7-bit opcode, and all 128 codes are valid instructions. How many outputs does the instruction decoder have?

Solution. A full decoder for a 7-bit opcode has 27 = 128 outputs, INS1 to INS128, one per instruction.

Problem 3: Write a Control Equation

Using the four instructions of this chapter (ADDM, ADDR, LOAD, BR), write the equation for MDRout and say how many AND gates it needs.

Solution. MDRout is active in T3 (fetch, all instructions), T6 of ADDM and T6 of LOAD: MDRout = T3 + T6·ADDM + T6·LOAD. Written this way it needs two 2-input AND gates and one 3-input OR gate. It can also be factored as T3 + T6·(ADDM + LOAD), which shares the T6 AND gate between both instructions.

Problem 4: One-hot vs Binary State Encoding

A hardwired controller is designed as an FSM with 10 states. How many flip-flops does it need with binary encoding and with one-hot (delay-element) encoding?

Solution. Binary: ⌈log2 10⌉ = 4 flip-flops. One-hot: one per state, 10 flip-flops. One-hot uses more flip-flops but its next-state and output logic is simpler and faster.

Problem 5: Effect of WMFC

With the Run signal, the counter stops while WMFC = 1 and MFC = 0. A memory read completes at the end of the 3rd clock cycle, counting the cycle in which Read is issued. In the ADD R1, (R3) sequence, the Read is issued in T1, and WMFC is in T2. How many clock cycles does step T2 last?

Solution. The read is issued in the T1 cycle (cycle 1), so MFC arrives at the end of cycle 3. T2 begins in cycle 2 and is held through cycle 3. T2 therefore lasts 2 clock cycles. This is why issuing Read early and doing useful work (PC + 4) in parallel matters. Note that exam questions sometimes simply say "a memory access takes k cycles" for each WMFC step; read the assumptions carefully.


Common Mistakes

  • Adding an opcode term to fetch steps. T1 to T3 are the same for every instruction, so their terms are just T1, T2, T3.

  • Forgetting End for every instruction. Each instruction's last step must assert End, otherwise the counter runs into the next step.

  • Forgetting the condition in conditional branches. The flag must appear in the term that ends a not-taken branch early.

  • Ignoring memory wait. Without Run (or an equivalent stall), the counter would move on before the data arrives.

  • Saying hardwired control cannot handle complex instructions. It can; it just becomes large and hard to design, which is why microprogramming was invented.


Interview Questions

What are the inputs of a hardwired control unit?

The timing signals from the step counter (decoded), the decoded opcode from IR, the condition flags (N, Z, C, V) and external inputs such as MFC and interrupt requests.

How is a control signal's logic equation derived?

Find every step of every instruction in which the signal is active. Each one gives an AND term (timing signal AND instruction line, plus any condition). The signal is the OR of those terms.

What does the End signal do?

It resets the step counter so the next clock starts step T1, the fetch of the next instruction.

How does the control unit wait for a slow memory?

The step counter is enabled by Run = NOT(WMFC AND NOT MFC). During a WMFC step the counter holds until MFC arrives, keeping the same step active.

Why do RISC processors prefer hardwired control?

Their instructions are few, simple and of fixed format, so the control logic stays small, and hardwired control is fast, which suits single-cycle-per-stage pipelines.

What are the main disadvantages of hardwired control?

It is inflexible (changes require redesign) and the logic becomes very complex for large instruction sets with many addressing modes.


Summary

  • The control unit produces the right control signals in the right clock cycle. A hardwired one does it with fixed logic.

  • Structure: step counter → step decoder (T1...Tn), IR → instruction decoder (INS lines), plus flags and external inputs, all feeding an AND-OR encoder. End resets the counter; Run stalls it while waiting for memory.

  • Each control signal = OR of (timing signal · instruction · condition) terms, e.g. Zin = T1 + T6·ADDM + T5·ADDR + T4·BR and End = T7·ADDM + T6·ADDR + T6·LOAD + T5·BR + T4·BRN·N' + T5·BRN.

  • Mano's basic computer: SC + 4×16 decoder (T0 to T15), opcode decoder D0 to D7, LD(AR) = T0 + T2 + D7'IT3 (with R' terms when interrupts are included).

  • Design methods: state table (binary FSM), delay element (one-hot), sequence counter.

  • Hardwired control is fast but inflexible; it suits RISC and pipelined processors. The alternative is the Microprogrammed Control Unit, covered next.