Control unit design, hardwired vs microprogrammed control, and pipelining with its hazards.
A program is a sequence of machine instructions; the processor fetches one instruction at a time and performs the operation it specifies. Instructions come from successive memory locations until a branch or jump is encountered.
The execution phase can perform one or more of these four kinds of operations (a classic Part-B list):
Answer with: (1) the fetch-phase equations IR ← [[PC]], PC ← [PC] + 4 and the diagram above → (2) the execution phase → (3) the four kinds of micro-operations listed here → then continue into §3–§6 (register transfers, ALU operation, memory read/write, complete instruction). The same material also carries (a–d).
Data, Instructions — option (a): data is the raw material; processing it yields the desired output in the form of instructions (an ordered set of which is a program).
Inside the processor, the registers, ALU and interconnecting bus are collectively called the data path. In the single-bus organization only one data item can be transferred over the bus in a clock cycle, so operations need several control steps.
Draw the figure above, then explain every register block in the same order as the bullets, finish with “data path = registers + ALU + interconnecting bus” and the MFC note.
Memory Address Register — option (d).
Data path — option (a).
Every register’s connection to the bus is controlled by two signals: Ri_in and Ri_out. All transfers happen inside time periods defined by the processor clock.
Example — transfer the contents of R1 to R4 (a favourite 2-mark sequence):
| Step | Signal(s) | What happens |
|---|---|---|
| 1 | R1_out = 1 | contents of R1 placed on the bus |
| 2 | R4_in = 1 | bus data loaded into R4 |
Because both actions need the bus in the same step and only the input latch waits for the clock edge, R1_out and R4_in can be asserted in the same clock cycle — the transfer completes in one step.
Define Ri_in / Ri_out, draw the register-bit gating figure, mention tri-state high-impedance, edge-triggered D flip-flop behaviour (Ri_in = 0 → feedback) and multiphase clocking. Close with the R1 → R4 two-signal example.
The ALU is combinational — no internal storage. Its two operands must be present simultaneously, but the single bus carries only one word per cycle, so one operand is parked in register Y and the result in register Z.
Why three steps? In step 2 the bus is busy carrying R2, so R1 must already sit in Y; and the ALU output cannot go straight onto the bus that is still carrying R2 — hence the temporary Z. The multiplexer’s SelectY signal routes Y to input A; Select4 would instead route the constant 4 (used to increment the PC).
State the no-internal-storage fact → the role of Y (operand staging) and Z (result holding) → write the 3-step signal sequence exactly as in the keybox → explain why each step is needed.
Memory access is asynchronous — response time varies (cache miss, memory-mapped I/O). The processor therefore issues the request and waits for MFC (WMFC) before continuing.
MDR’s connection to the outside world needs special care: it sits between the internal bus and the external memory-data lines, so tri-state gates controlled by MDR_inE / MDR_outE decide which side drives it.
Note the read/write asymmetry: a write keeps the data stable on the data lines until the memory completes, whereas a read loads MDR when MFC arrives. Both end with WMFC — the only step that can stretch over many clock cycles.
For (c): the Move (R1), R2 sequence + timing diagram + MFC/WMFC meaning + MDR connection figure. For (d): the Move R2, (R1) sequence; point out address → data → Write order and the final WMFC.
Putting everything together: Add (R3), R1 — add the contents of the memory location pointed to by R3 into R1. The fetch phase is common to every instruction; the execution phase depends on the opcode.
| Step | Control signals | Action |
|---|---|---|
| 1 | PC_out, MAR_in, Read, Select4, Add, Z_in | fetch begins; Z ← [PC] + 4 |
| 2 | Z_out, PC_in, WMFC | PC updated; wait for memory |
| 3 | MDR_out, IR_in | instruction loaded into IR |
| 4 | R3_out, MAR_in, Read | operand address out; read starts |
| 5 | R1_out, Y_in, WMFC | R1 staged in Y; wait for MFC |
| 6 | MDR_out, SelectY, Add, Z_in | Z ← [R1] + [memory operand] |
| 7 | Z_out, R1_in, End | result into R1; fetch next instruction |
The End signal resets the control-step counter so the next fetch cycle starts immediately. Steps 1–3 are the fetch phase; steps 4–7 the execution phase.
In step 4 the sign-extended offset comes from the IR over the bus (ALU input B) while SelectY feeds input A; the sum is the target address, which step 5 loads into the PC. A conditional branch tests the condition-code flags first and updates the PC only if the condition holds.
The 7-step table above is the heart of the answer — practise writing it until automatic. The same table reappears as the worked example inside the hardwired-control answer (§8).
The single bus forces long control sequences (one transfer per cycle). Most commercial processors therefore provide multiple internal paths so that several transfers happen in parallel — fewer control steps per instruction.
| Single-bus structure | Multi-bus structure | |
|---|---|---|
| Paths | one common bus | several internal buses (e.g. A, B, C) |
| Transfers / cycle | one data item | multiple, in parallel |
| Control sequence | long | short |
| Hardware cost | low | more (extra ports, buses) |
| Step | Action | Remarks |
|---|---|---|
| 1 | PC_out, R=B, MAR_in, Read, IncPC | PC passes through ALU (R=B) into MAR; PC incremented |
| 2 | WMFC | wait for Memory-Function-Complete |
| 3 | MDR_outB, R=B, IR_in | instruction from MDR (bus B) through ALU into IR |
| 4 | R4_outA, R5_outB, SelectA, Add, R6_in, End | R4, R5 out on buses A, B; sum over bus C into R6 — done in one cycle |
Give the single- vs multi-bus comparison table → the three-bus figure with the register-file ports → the Add R4,R5,R6 step table → note the disappearance of Y/Z and the role of the incrementer unit.
The control unit must generate the control signals in proper sequence. In a hardwired unit they are produced by combinational circuitry — the control unit is designed as a finite state machine. Inflexible but fast — appropriate for simpler machines (RISC).
The required control signals are determined by four pieces of information:
The decoder/encoder block is a combinational circuit that turns these inputs into the control outputs. Two more signals manage the counter itself:
Example logic. Looking at where Z_in is asserted in the Add (R3),R1 and Branch sequences (steps T1, T6 of ADD; T4 of BR):
Each new instruction simply ORs its own terms into the equations — that is also exactly why the design is called inflexible: the logic must be rewired when the instruction set changes. The simplest implementation method is the state-table method; the sequence-counter method is the most widely used.
Draw the block diagram → list the four input groups → explain counter/RUN/END → derive the two example equations → close with the hardwired-vs-microprogrammed table from §9. Also serves.
• the microprogrammed control unit is the flexible one (b). • combinational-logic signal generation = hardwired (d). • simplest method of implementing a hardwired unit = State Table Method (a) — note the sequence-counter method is only the most popular.
Here the control signals are generated by a micro-program — a sequence of 0s and 1s stored like machine-language code. If PC_out is needed in a step, the bit allocated to PC_out in that word is set to 1. Flexible but slow — appropriate for complex machines (CISC).
Define CW / microinstruction / microroutine / control store → draw the block diagram (IR → generator → µPC → control store → CW, with the branch-address feedback) → explain the three µPC-loading cases → walk through the Branch-N microroutine listing of §10. is answered by the comparison keybox (with §8).
Microprogrammed control unit — option (b).
The naive approach — one bit per control signal — produces very long microinstructions, because there are many signals yet only a few are 1 in any given step (poor bit-space use). The fix: exploit that most signals are mutually exclusive.
Encoding: group mutually exclusive signals into the same field; at most one micro-operation per field, binary-coded. Examples: a 16-operation ALU needs only 4 bits; PC_out, MDR_out, Z_out, Offset_out, R0_out … Temp_out (9 register-output signals) share one group and again fit in 4 bits. Most fields also keep one inactive code meaning “no action”. This is the vertical style; the one-bit-per- signal extreme is the horizontal style (faster, longer words).
| Addr | Microroutine of Branch N (sample listing) |
|---|---|
| 0 | PC_out, MAR_in, Read, Select4, Add, Z_in |
| 1 | Z_out, PC_in, WMFC |
| 2 | MDR_out, IR_in |
| 3 | branch to starting address of the appropriate microroutine |
| 25 | If N = 0 then branch to microinstruction 0 |
| 26 | Offset-field-of-IR_out, SelectY, Add, Z_in |
| 27 | Z_out, PC_in, End |
The listing shows the conditional jump from address 25 back to 0 when N = 0: the branch is simply not taken by the machine. The target address of such conditional jumps is produced by the starting & branch address generator (which now also receives the condition codes and external inputs).
After the block diagram (§9), add: the grouping/encoding idea with both examples, the sample Branch-N listing, and the remark that the generator produces conditional-jump target addresses.
Two ways to make a processor faster: faster circuit technology, or arrange the hardware so that more than one operation is performed at the same time. Pipelining is the second idea: like an assembly line, the execution of the current instruction overlaps the execution of subsequent ones — instruction-level parallelism.
| Clock cycle → | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| Fetch unit | I1 | I2 | I3 | I4 | I5 |
| Execute unit | — | I1 | I2 | I3 | I4 |
By the end of cycle 2 both units are busy — and they stay busy. With four stages each instruction passes through four dedicated hardware units, buffers B1–B3 between them:
| Instruction ↓ / cycle → | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| I1 | F | D | E | W | |||
| I2 | F | D | E | W | |||
| I3 | F | D | E | W | |||
| I4 | F | D | E | W |
Every stage is controlled by one clock cycle; a new instruction enters the pipe each cycle and one finishes each cycle (once full). The role of cache memory: each stage must complete in one clock period, but main-memory access is far slower — so a cache is added, and if it sits on the processor chip its access time matches the pipeline stage time.
Definition + assembly-line analogy → 2-stage hardware & timeline → 4-stage hardware, F/D/E/W and the timeline → throughput argument (§12) → mention cache. All three Part-B questions share this one answer.
• the term for simultaneous access to a resource (physical or logical) is Concurrency (d). • pipelining is also called the Assembly-line operation (b).
Pipelining increases the instruction throughput — the number of instructions completed per unit time — so the program runs faster and its total execution time falls, without making any single instruction faster.
Real pipelines stall. A cache miss in a fetch freezes everything behind it:
| Clock cycle → | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| F (I1) | F1 | ||||||
| F (I2) | F2 (miss — wait) | F2 | F2 | ||||
| D | — | — | D1 | D2 | |||
| E | — | — | E1 | E2 | |||
| W | — | — | W1 |
The same happens when one stage simply needs more cycles — e.g. I2 takes 3 cycles in its execute stage (cycles 4, 5, 6): in cycles 5 and 6 the write stage must be told to do nothing, because it has no data to work with.
Define throughput → give the S = nk/(k+n−1) derivation and the “proportional to stages” remark → then honestly note the interruptions (cache miss, unequal stage length) that bring us to hazards (§13–§14).: to increase memory-access speed in pipelining we use Cache (c).
A hazard is any situation that prevents the next instruction in the stream from executing during its designated clock cycle. Hazards are the major hurdle of pipelining — they drag performance below the ideal speed-up and make stalls necessary. Three classes: structural, data, control/instruction.
Structural example: if one memory pipeline serves both data and instructions, an instruction containing a data-memory reference conflicts with the instruction fetch of a later instruction. Remedy: stall one clock cycle when the data access occurs — the inserted idle period is called a pipeline bubble. Stalls push the CPI above its ideal value of 1 (example: Load x(R1), R2 with unified memory).
Data example:
ADD R2, R3, R1 ; writes R1 SUB R4, R1, R5 ; reads R1 — too early!
The ADD writes R1 in its WB stage, but SUB reaches its ID stage before that write happens — this is the classic data hazard. Its three types (asked by name in Part C):
| Type | Also called | Pattern |
|---|---|---|
| RAW | true / flow dependence | write…then read — the ADD/SUB case above |
| WAW | output dependence | two instructions write the same register |
| WAR | anti-dependence | a later instruction writes a register an earlier one still reads |
Forwarding routes the ALU result of ADD straight into SUB’s Execute stage instead of waiting for it to be written back. It cannot always help: after
LD 0(R2), R1 ; R1 ← memory DSUB R4, R1, R5 ; needs R1 — 1 stall even with forwarding AND R6, R1, R7 ; satisfied by forwarding OR R8, R1, R9 ; satisfied by forwardingMEM
B6: define hazard → three classes with the structural memory-conflict example and the ADD/ SUB data example + forwarding. C1: name RAW / WAW / WAR with one-line causes, then the LD/DSUB/ AND/OR stall sequence. C2: performance gain (§12) + the three hazard classes as the hurdles.
Whenever the stream of instructions supplied by the fetch unit is interrupted, the pipeline stalls. Branches are the usual culprit: the processor does not know where to fetch next until the branch resolves.
Instruction hazards → the 2-stage branch/flush story → branch penalty & how to reduce it → instruction queue / dispatch unit (this figure) → then continue with delayed branch and prediction in §15 for the second half of the answer.
A conditional branch adds a further hazard: the branch condition may depend on the result of a preceding instruction, so the decision cannot be made until that instruction finishes executing.
Delayed branch. The location following the branch is the branch delay slot. Its instruction is fetched anyway, so we would like it to be fully executed whether or not the branch is taken — the objective is to place useful instructions in the slot. Success depends on how often the compiler can reorder instructions:
| (a) no useful instruction | (b) from the target | (c) from before the branch |
|---|---|---|
| branch — delay slot filled with NOP | target instruction moved up into the slot | instruction preceding the branch moved into the slot (if legal) |
Branch prediction. The simplest form: assume not taken and keep fetching in sequential address order. Until the branch is evaluated, execution along the predicted path is done on a speculative basis — instructions are executed before the processor is certain they are in the correct sequence, so no registers or memory locations may be updated until confirmation. An incorrect prediction means discarding the speculative work and fetching the correct path.
Delay slot + the three filling strategies → speculative execution → static vs dynamic → draw both state diagrams and state their rules. (Slide wording “if taken it changes to ST” means it moves one step toward ST: LNT → LT → ST.)
Some instructions are much better suited to pipelined execution than others. The two big design questions are the addressing modes and the condition-code flags.
Addressing modes. In choosing modes for a pipelined processor, weigh each mode’s effect on instruction flow: (1) its side effects, (2) how far the mode makes the pipeline stall, (3) how likely compilers are to use it. Complex modes save instruction count — Load (X(R1)), R2 needs an extra memory access and stalls the pipe — while the simple equivalent pair Add #X, R1, R2 / Load (R2), R2 flows smoothly. Complex modes are therefore not suitable for pipelined execution: their advantage (fewer instructions / program space) is outweighed by stalls, extra decoding hardware and compiler inconvenience.
Conditional codes. An optimizing compiler reorders instructions to hide stalls, but must not change the outcome of the computation — and the dependency introduced by condition-code flags reduces that reordering flexibility. Two conclusions: