Sub topic 16
Microprogrammed control units and the control store
This chapter assumes you know the fetch sequence as register transfers, the idea of control signals, and how a hardwired control unit generates them from the opcode and a timing counter. Here you will see the alternative: store the control signals in a small memory and read them out step by step.
The core idea
A microprogrammed control unit replaces the random logic of a hardwired design with a memory called the control store. Each word in the control store is a microinstruction. A microinstruction specifies which control signals are active during one clock step, and it can also say which microinstruction to run next.
The sequence of microinstructions that implements one machine instruction is a microroutine. The collection of all microroutines is the microprogram, and it is held in the control store, usually a ROM.
Two levels of "program" exist, and mixing them up is a common error:
- A machine instruction is what the programmer writes. It lives in main memory and is fetched into the IR.
- A microinstruction is what the control unit executes. It lives in the control store and is fetched into the control data register.
Each machine instruction is executed by running several microinstructions. Each microinstruction normally takes one clock cycle.
Components
| Component | Role |
|---|---|
| Control store (CS) | ROM holding all microinstructions |
| Control address register (CAR), also called microprogram counter | Holds the address of the next microinstruction |
| Control data register (CDR), also called microinstruction register | Holds the microinstruction being executed |
| Opcode mapping logic | Converts the opcode in the IR into the starting address of a microroutine |
| Next-address logic | Chooses what loads into the CAR next |
The CDR often has two parts. The control field drives the datapath control signals. The address field, together with a condition-select field, tells the next-address logic where to go next.
How a machine instruction is executed
- The fetch microroutine sits at a fixed address, for example address 0. It performs the fetch register transfers: MAR <- PC, then MDR <- M[MAR] with PC <- PC + 1, then IR <- MDR.
- The last microinstruction of the fetch routine tells the next-address logic to use the mapping logic. The opcode in the IR is converted into the address of the matching execute microroutine.
- The execute microroutine runs, one microinstruction per clock cycle.
- The last microinstruction of the execute routine sends the CAR back to the fetch routine address.
A simple mapping function places each microroutine at an address derived from the opcode, for example by appending zeros: address = opcode followed by 00. That reserves 4 microinstruction slots per opcode. Longer routines need an unconditional branch to a spare area.
Sequencing: choosing the next address
The next-address logic usually chooses among these sources:
- Increment: CAR <- CAR + 1. This is the default for straight-line microcode.
- Branch address: CAR <- address field of the current microinstruction. This is used for jumps, and for conditional jumps when the selected flag is true.
- Mapping: CAR <- address derived from the IR opcode, used once per instruction after fetch.
- Return: CAR <- fetch address, or a saved address if the design has a micro-subroutine mechanism.
Conditional branching works through a condition-select field. It names one flag, such as zero or carry. If the flag is true, the branch address loads. Otherwise CAR + 1 is used. This lets the microprogram handle addressing-mode variations or loop-like behavior, for example repeated shifts in a multiply routine.
Mapping per addressing mode
One routine can serve many addressing modes if the microprogram branches on the mode field. The shared effective-address computation is written once. Each opcode routine then jumps to it, which saves control store space.
Example microroutine
The following is a symbolic microprogram for a hypothetical machine. The ADD routine is for ADD R1, [addr], where the address field is in the IR. Signals are written as register transfers.
Address Microinstruction Next
0 MAR <- PC CAR+1
1 MDR <- M[MAR]; PC <- PC + 1 CAR+1
2 IR <- MDR MAP (use opcode)
...
ADD:
40 MAR <- IR.address CAR+1
41 MDR <- M[MAR] CAR+1
42 R1 <- R1 + MDR; set flags goto 0The fetch routine uses 3 microinstructions. ADD uses 3 more, so this ADD costs 6 clock cycles in total. A hardwired design could merge some of these steps, because random logic can issue several transfers in one step wherever the datapath allows.
Sizing the control store
GATE questions often ask for the size of the control store, so the arithmetic matters.
The control store has one word per microinstruction. Its capacity is:
- number of words = number of distinct microinstruction addresses, and
- word width = control field bits + condition-select bits + address field bits.
The address field must be able to name any control store location, so its width is log2(number of words), rounded up.
import math
def control_store_size(num_microinstr, control_signals, num_conditions,
encoded_control_bits=None):
"""Return (address_bits, word_bits, total_bits).
control_signals: number of control bits if one bit per signal
(horizontal). Pass encoded_control_bits to override.
num_conditions: number of selectable conditions; 0 means no
conditional branching, so no condition-select field.
"""
addr_bits = math.ceil(math.log2(num_microinstr))
control_bits = (encoded_control_bits
if encoded_control_bits is not None
else control_signals)
cond_bits = math.ceil(math.log2(num_conditions)) if num_conditions > 1 else 0
word_bits = control_bits + cond_bits + addr_bits
return addr_bits, word_bits, num_microinstr * word_bits
# 1024 microinstructions, 40 control signals (one bit each), 8 conditions
print(control_store_size(1024, 40, 8)) # (10, 53, 54272)Here the address field is 10 bits, the condition field is 3 bits, and the control field is 40 bits, so each word is 53 bits and the store holds 1024 × 53 = 54,272 bits, which is 6784 bytes.
Typical GATE variants
- The question gives the number of machine instructions, microinstructions per instruction, and shared routines. Add the fetch routine and any shared effective-address routine once, not per instruction.
- The question gives a condition count that includes "unconditional". Check whether the unconditional case needs its own code.
- The question asks only for the size of the address field, which is just log2 of the number of words, rounded up.
- The question gives a bit-width for the mapping and asks how many opcodes fit. The count of opcodes times the slots per routine gives the minimum control store size.
Advantages and limits
Microprogramming makes the control unit regular. Changing the behavior of an instruction means changing ROM contents rather than redrawing logic. Complex instructions with many steps are easy to add. A writable control store even allows the instruction set to be updated or emulated.
The cost is speed. Each microinstruction requires a control store read, which is slower than a gate delay, and the next-address logic adds delay too. The later chapter on choosing between the two styles compares these costs in detail.
Common errors
- Counting the control store as if it held machine instructions. It holds microinstructions.
- Forgetting that the fetch routine is shared and counting it once per instruction.
- Using the opcode width for the address field. The address field depends on the number of control store words.
- Forgetting the condition-select field when the design supports conditional branches.
- Treating the CAR as a counter only. It can also load from the mapping logic and the branch field.
Exercise
A microprogrammed control unit has a control store of 2048 words. Its microinstruction has 36 bits for control signals, a condition-select field that chooses among 16 conditions, and an address field wide enough for any control store location. How many bits does the control store hold in total, and what is the width of one microinstruction?
Show answer
The address field needs log2(2048) = 11 bits. The condition-select field needs log2(16) = 4 bits. The microinstruction width is 36 + 4 + 11 = 51 bits. The control store holds 2048 × 51 = 104,448 bits, which is 13,056 bytes.
Exercise
In a design that appends two zero bits to the opcode to form a microroutine address, the opcode is 6 bits. What is the lowest control store address of the routine for opcode 010011, and how many microinstructions can that routine hold before it needs a branch?
Show answer
The address is 010011 followed by 00, which is 01001100 in binary, or 76 in decimal. Appending two bits gives 2^2 = 4 slots, so the routine can hold 4 microinstructions before it needs a branch.