Loading lessons...
Microprogrammed Control: Control Memory, Address Sequencing & the Microprogram
Microprogrammed Control: Control Memory, Address Sequencing & the Microprogram
In hardwired control (lesson 29) every control signal comes from a fixed network of gates. Microprogrammed control stores the control signals of each step as a word in a special memory, and steps through those words like a tiny program. This lesson covers the terms, how the next microinstruction is chosen (address sequencing), Mano's example microprogram, and the design of the microprogram sequencer.
1. Basic Terms
| Term | Meaning |
|---|---|
| Control word | a string of 1s and 0s whose bits are the control variables (one per control signal) for one step |
| Microoperation | an elementary operation done in one clock (as in lesson 27) |
| Microinstruction | a control word stored in control memory, together with information about the next microinstruction |
| Microprogram | a sequence of microinstructions |
| Control memory | the memory holding the microprograms; usually a ROM (writable control memory makes the computer microprogrammable: the instruction set can be changed) |
| Control address register (CAR) | holds the address of the next microinstruction |
| Control data register | optional; holds the microinstruction while the next address is computed (pipelining) |
| Sequencer (next-address generator) | computes the next address from the current microinstruction, status bits and the instruction |
Microprogrammed control organisation
Each clock pulse: the control memory outputs the word at CAR, its control bits perform the microoperations, and the sequencer loads CAR with the next address. Changing the instruction set means changing the ROM contents, not the wiring.
| Hardwired | Microprogrammed | |
|---|---|---|
| Speed | faster | slower (one control-memory access per step) |
| Flexibility | changes need a redesign | changes need a new microprogram |
| Complex instruction sets | costly, error-prone | systematic and cheap |
| Typical use | RISC | CISC |
2. Address Sequencing
Each machine instruction has its own routine of microinstructions in control memory. The sequencer must:
- Increment CAR to go to the next microinstruction of a routine.
- Branch (unconditionally, or on a status bit) to a given address.
- Map the opcode of the instruction to the address of its routine.
- Call a subroutine of microinstructions (common sequences such as the indirect-address calculation) and return from it, using a subroutine register (SBR).
The routine for instruction fetch is the same for every instruction: it reads the instruction into the instruction register. Then a mapping turns the opcode into the address of the routine that executes it.
2.1 Mapping
A simple mapping places the opcode bits inside a fixed pattern. In Mano's example the 4-bit opcode is mapped to the 7-bit address 0 xxxx 00:
Microinstruction format and opcode mapping
Each routine therefore starts at a multiple of 4 and has four words available. A routine that needs more can jump to free space beyond address 64. A more flexible mapping uses a small mapping ROM (or PLD) whose output is the routine address.
Find the routine addresses of opcodes 0000, 0001, 0010, 0011 and 1011 with the mapping 0 xxxx 00.
- 0000 → 0 0000 00 = 0; 0001 → 0 0001 00 = 4.
- 0010 → 0 0010 00 = 8; 0011 → 0 0011 00 = 12.
- 1011 → 0 1011 00 = 44.
3. Mano's Microprogrammed Computer
The example computer has a 2048 × 16 main memory, registers PC and AR (11 bits), DR and AC (16 bits), and a 128 × 20 control memory. Its instructions have I (bit 15), a 4-bit opcode (bits 11-14) and an 11-bit address. Four instructions are microprogrammed: ADD (0000), BRANCH (0001, branch if AC < 0), STORE (0010) and EXCHANGE (0011).
3.1 Microinstruction format
| Field | Bits | Purpose |
|---|---|---|
| F1, F2, F3 | 3 + 3 + 3 | three microoperation fields; each selects one of 7 microoperations (000 = none), so up to 3 can run together |
| CD | 2 | condition: 00 U (always 1), 01 I = DR(15), 10 S = AC(15), 11 Z (AC = 0) |
| BR | 2 | branch type (table below) |
| AD | 7 | address field (128 words) |
| BR | Symbol | Function |
|---|---|---|
| 00 | JMP | CAR ← AD if the condition is 1; CAR ← CAR + 1 otherwise |
| 01 | CALL | CAR ← AD, SBR ← CAR + 1 if the condition is 1; CAR ← CAR + 1 otherwise |
| 10 | RET | CAR ← SBR (return from subroutine) |
| 11 | MAP | CAR(2-5) ← DR(11-14), CAR(0, 1, 6) ← 0 |
Some microoperations (F1): ADD (001), CLRAC, INCAC, DRTAC (100: AC ← DR), DRTAR (101: AR ← DR(0-10)), PCTAR (110: AR ← PC), WRITE (111: M[AR] ← DR). F2 includes READ (100: DR ← M[AR]) and ACTDR (101: DR ← AC). F3 includes INCPC (101: PC ← PC + 1) and ARTPC (110: PC ← AR).
3.2 Symbolic microprogram
Each line has a label, the microoperations, CD, BR and AD (a symbol, NEXT for the next address, or blank):
| Address | Label | Microops | CD | BR | AD |
|---|---|---|---|---|---|
| 0 | ADD: | NOP | I | CALL | INDRCT |
| 1 | READ | U | JMP | NEXT | |
| 2 | ADD | U | JMP | FETCH | |
| 4 | BRANCH: | NOP | S | JMP | OVER |
| 5 | NOP | U | JMP | FETCH | |
| 6 | OVER: | NOP | I | CALL | INDRCT |
| 7 | ARTPC | U | JMP | FETCH | |
| 8 | STORE: | NOP | I | CALL | INDRCT |
| 9 | ACTDR | U | JMP | NEXT | |
| 10 | WRITE | U | JMP | FETCH | |
| 12 | EXCHANGE: | NOP | I | CALL | INDRCT |
| 13 | READ | U | JMP | NEXT | |
| 14 | ACTDR, DRTAC | U | JMP | NEXT | |
| 15 | WRITE | U | JMP | FETCH | |
| 64 | FETCH: | PCTAR | U | JMP | NEXT |
| 65 | READ, INCPC | U | JMP | NEXT | |
| 66 | DRTAR | U | MAP | ||
| 67 | INDRCT: | READ | U | JMP | NEXT |
| 68 | DRTAR | U | RET |
How it works:
- FETCH (64 to 66): AR ← PC; DR ← M[AR], PC ← PC + 1; AR ← DR(0-10) and map the opcode.
- ADD: if I = 1, CALL INDRCT, which reads the effective address (AR ← M[AR] via DR) and returns. Then read the operand and add.
- BRANCH: if AC is negative (S = 1) go to OVER, which computes the effective address and loads PC; else back to FETCH.
- EXCHANGE: read the operand into DR; then ACTDR, DRTAC in one microinstruction swaps AC and DR (both registers are read before either changes); then write DR to memory.
Give the 20-bit words at addresses 0, 2 and 64.
- Address 0: NOP (000 000 000), CD = I (01), BR = CALL (01), AD = INDRCT = 67 = 1000011: 000 000 000 01 01 1000011.
- Address 2: ADD in F1 (001), U (00), JMP (00), AD = FETCH = 64 = 1000000: 001 000 000 00 00 1000000.
- Address 64: PCTAR in F1 (110), U JMP NEXT = 65 = 1000001: 110 000 000 00 00 1000001.
A control memory has 1024 words of 32 bits. The microinstruction has three fields: microoperations, a condition select for one of 16 status bits, and an address. How many bits are in each field?
- Address: 1024 = 210 words, so 10 bits.
- Condition select: 16 status bits, so 4 bits.
- Microoperations: 32 - 10 - 4 = 18 bits.
A processor has 46 control signals, at most 3 used in one microinstruction, and they fall into three groups of 15 mutually exclusive signals each (plus one spare). Compare the field width with one bit per signal and with encoded fields.
- One bit per signal (horizontal): 46 bits, any combination possible.
- Encoded (vertical): each group of 15 signals plus "none" needs ⌈ log2 16 ⌉ = 4 bits; three groups need 12 bits (plus 1 for the spare signal), and a decoder per field.
4. Design of the Control Unit
The bits of F1, F2 and F3 are decoded by three 3 × 8 decoders; each output drives the control inputs of the registers (for example, the DRTAR output enables LD of AR with DR as its source, through a multiplexer at AR's input).
4.1 The microprogram sequencer
Microprogram sequencer
- MUX1 chooses the next CAR value from four sources: the incrementer (CAR + 1), SBR (return address), the AD field (branch), or the mapping of DR(11-14).
- MUX2 chooses the status bit named by CD (1, I, S or Z); its output is the test bit T.
- The input logic combines BR (I1 I0) and T into the MUX1 select (S1 S0) and the load signal L of SBR:
| BR | I1 | I0 | T | MUX1 S1 S0 | L | Result |
|---|---|---|---|---|---|---|
| JMP | 0 | 0 | 0 | 00 | 0 | CAR + 1 |
| JMP | 0 | 0 | 1 | 10 | 0 | AD |
| CALL | 0 | 1 | 0 | 00 | 0 | CAR + 1 |
| CALL | 0 | 1 | 1 | 10 | 1 | AD, SBR ← CAR + 1 |
| RET | 1 | 0 | x | 01 | 0 | SBR |
| MAP | 1 | 1 | x | 11 | 0 | mapping |
From the table: when I1 = 0 (JMP, CALL), S1 = T and S0 = 0; when I1 = 1 (RET, MAP), S1 = I0 and S0 = 1. SBR is loaded only for CALL with T = 1. So
Trace CAR for an ADD instruction with I = 1.
- FETCH: 64, 65, 66 (MAP to 0).
- 0: I = 1, CALL INDRCT: SBR ← 1, CAR ← 67.
- 67, 68: read the effective address; RET: CAR ← SBR = 1.
- 1: READ; 2: ADD, JMP FETCH.
5. Verilog: Sequencer and Control Memory
The model stores the microprogram in a 128 × 20 ROM and implements the four branch types and the four conditions exactly as tabled. The testbench sets DR to an instruction and follows CAR from FETCH until control returns to FETCH:
// Microprogram sequencer and control memory (Mano's microprogrammed computer).
// Microinstruction: F1(3) F2(3) F3(3) CD(2) BR(2) AD(7) = 20 bits
module micro_sequencer (
input clk,
input rst,
input [15:0] dr, // instruction word: I = dr[15], opcode = dr[14:11]
input ac15, // sign of AC
input aczero, // AC = 0
output reg [6:0] car, // control address register
output [19:0] mi // current microinstruction
);
reg [19:0] rom [0:127];
reg [6:0] sbr; // subroutine register
wire [1:0] cd = mi[10:9]; // condition field
wire [1:0] br = mi[8:7]; // branch field
wire [6:0] ad = mi[6:0]; // address field
reg t;
assign mi = rom[car];
always @(*)
case (cd) // condition select
2'b00: t = 1'b1; // U: always
2'b01: t = dr[15]; // I: indirect bit
2'b10: t = ac15; // S: AC negative
default: t = aczero; // Z: AC is zero
endcase
always @(posedge clk)
if (rst) car <= 7'd64; // start at FETCH
else
case (br)
2'b00: car <= t ? ad : car + 1'b1; // JMP
2'b01: if (t) begin // CALL
sbr <= car + 1'b1;
car <= ad;
end else car <= car + 1'b1;
2'b10: car <= sbr; // RET
default: car <= {1'b0, dr[14:11], 2'b00}; // MAP
endcase
integer i;
initial begin
for (i = 0; i < 128; i = i + 1) rom[i] = 20'b000_000_000_00_00_1000000;
// F1 F2 F3 CD BR AD
rom[0] = 20'b000_000_000_01_01_1000011; // ADD: NOP I CALL INDRCT
rom[1] = 20'b000_100_000_00_00_0000010; // READ U JMP NEXT
rom[2] = 20'b001_000_000_00_00_1000000; // ADD U JMP FETCH
rom[4] = 20'b000_000_000_10_00_0000110; // BRANCH:NOP S JMP OVER
rom[5] = 20'b000_000_000_00_00_1000000; // NOP U JMP FETCH
rom[6] = 20'b000_000_000_01_01_1000011; // OVER: NOP I CALL INDRCT
rom[7] = 20'b000_000_110_00_00_1000000; // ARTPC U JMP FETCH
rom[8] = 20'b000_000_000_01_01_1000011; // STORE: NOP I CALL INDRCT
rom[9] = 20'b000_101_000_00_00_0001010; // ACTDR U JMP NEXT
rom[10] = 20'b111_000_000_00_00_1000000; // WRITE U JMP FETCH
rom[64] = 20'b110_000_000_00_00_1000001; // FETCH: PCTAR U JMP NEXT
rom[65] = 20'b000_100_101_00_00_1000010; // READ, INCPC U JMP NEXT
rom[66] = 20'b101_000_000_00_11_0000000; // DRTAR U MAP
rom[67] = 20'b000_100_000_00_00_1000100; // INDRCT:READ U JMP NEXT
rom[68] = 20'b101_000_000_00_10_0000000; // DRTAR U RET
end
endmodule
module tb;
reg clk = 0, rst = 1;
reg [15:0] dr;
reg ac15 = 0;
wire [6:0] car;
wire [19:0] mi;
integer k;
micro_sequencer u (clk, rst, dr, ac15, 1'b0, car, mi);
always #5 clk = ~clk;
// run one instruction from FETCH until control returns to FETCH
task run(input [15:0] w, input s, input [8*26:1] name);
begin
dr = w;
ac15 = s;
$write("%0s:", name);
k = 0;
// control is at FETCH (64) now; follow it until it comes back
while (k == 0 || car != 7'd64) begin
$write(" %0d", car);
@(negedge clk);
k = k + 1;
end
$display(" (%0d microinstructions)", k);
end
endtask
initial begin
@(negedge clk);
rst = 0; // CAR = 64 (FETCH) now
run(16'h0000, 0, "ADD direct");
run(16'h8000, 0, "ADD indirect");
run(16'h0800, 0, "BRANCH, AC positive");
run(16'h0800, 1, "BRANCH, AC negative");
run(16'h1000, 0, "STORE direct");
$finish;
end
endmoduleEvery routine starts with the fetch at 64-66, maps to its own block of four words, and the indirect ADD calls INDRCT (67, 68) and returns to word 1, as traced in Example 5. BRANCH goes to OVER (6) only when AC is negative:
ADD direct: 64 65 66 0 1 2 (6 microinstructions)
ADD indirect: 64 65 66 0 67 68 1 2 (8 microinstructions)
BRANCH, AC positive: 64 65 66 4 5 (5 microinstructions)
BRANCH, AC negative: 64 65 66 4 6 7 (6 microinstructions)
STORE direct: 64 65 66 8 9 10 (6 microinstructions)Key points to remember
- Control memory (ROM) holds microinstructions; CAR addresses it; the sequencer finds the next address.
- Sequencing: increment, branch (conditional), map the opcode, call/return with SBR.
- Mapping 0 xxxx 00 gives each routine 4 words (opcode 0011 → 12).
- Mano's format: F1 F2 F3 (3 bits each), CD (2), BR (2), AD (7) = 20 bits; memory 128 × 20.
- Sequencer: MUX1 (CAR + 1, SBR, AD, mapping), MUX2 (U, I, S, Z), input logic S1 = I1' T + I1 I0, S0 = I1, L = I1' I0 T.
📝 IPU End-Term Exam Corner (5-10 Marks)
- Q1. Explain the organisation of a microprogrammed control unit. Define control memory, control word, microinstruction, microprogram, CAR and sequencer. Compare with hardwired control. (10 Marks)
- Q2. Explain address sequencing: incrementing, branching, mapping and subroutines. Show the mapping of an opcode to a microinstruction address. (5 Marks)
- Q3. Give the microinstruction format of Mano's example computer and write the symbolic microprogram for the fetch routine and the ADD instruction. (10 Marks)
- Write: F1 F2 F3 CD BR AD, the BR table, FETCH at 64, INDRCT at 67, ADD at 0.
- Q4. Draw the microprogram sequencer and derive its input logic. (10 Marks)
- Q5. A control memory has 2048 words of 40 bits and selects one of 32 status bits. Find the field sizes. (2.5 Marks)