Computer ArchitectureUnit 514 min read
Control Unit Design & Microprogramming: Working, Types, Speed vs. Hardwired
Unit 5 of Computer Architecture covers the design of control units—both hardwired and microprogrammed—explaining how microinstructions work, their sequencing, and the trade-offs between horizontal/vertical formats. It also contrasts microprogrammed control with hardwired logic, using real-world examples like eSewa’s tr
TAKEAWAYS:
- A control unit decodes instructions and generates control signals to coordinate CPU operations, using either hardwired logic or microprogramming.
- Microprogramming replaces hardwired control logic with a sequence of microinstructions stored in control memory, improving flexibility but adding latency.
- Horizontal microinstructions encode all control signals in parallel (faster, larger memory), while vertical microinstructions use compressed fields (slower, smaller memory).
- Microinstruction sequencing (via next-address fields) ensures correct execution order, with conditional branches for loops or exceptions.
- Microprogrammed control is slower than hardwired but easier to modify, making it ideal for complex ISAs like x86.
- Real-world uses include eSewa’s payment validation (microprogrammed control in payment processors) and Ncell’s billing systems (microcode for SIM-based authentication).
1. What is a Control Unit?
The control unit (CU) is the "brain" of the CPU that:
- Fetches instructions from memory.
- Decodes them into control signals (e.g., "load data from RAM," "add two registers").
- Coordinates the ALU, registers, and memory to execute instructions.
How It Works
- Instruction Fetch: CU fetches the next instruction from the Program Counter (PC).
- Decode: Interprets the opcode (e.g.,
ADD,JMP). - Execute: Generates signals to activate the correct hardware (e.g.,
Reg[R1] → ALU → Reg[R2]). - Writeback: Stores results in registers/memory.
2. Hardwired vs. Microprogrammed Control Units
| Feature | Hardwired Control Unit | Microprogrammed Control Unit |
|---|---|---|
| Design | Custom logic gates (combinational circuits). | Microinstructions stored in control memory. |
| Speed | Faster (direct signal paths). | Slower (fetches microinstructions sequentially). |
| Flexibility | Hard to modify (requires rewiring). | Easy to update (change microcode). |
| Complexity | Simple for RISC ISAs. | Handles complex CISC ISAs (e.g., x86). |
| Cost | Lower for simple designs. | Higher (needs extra memory). |
| Example Use | ARM processors (RISC). | Intel x86 (CISC). |
Why Microprogramming?
- Simplifies complex ISAs: CISC instructions (e.g.,
MUL,DIV) are broken into microoperations. - Easier debugging: Microcode can be updated without changing hardware.
- Standardization: Same microcode can run on different CPUs (e.g., emulating old x86 on ARM).
3. Microprogrammed Control Unit: Core Concepts
A. Control Memory
- Stores microinstructions (like a program for the CU).
- Each microinstruction corresponds to a control signal (e.g., "enable ALU," "load register").
- Addressed by:
- Instruction opcode (for the first microinstruction).
- Next-address field (for subsequent microinstructions).
B. Microinstruction Formats
1. Horizontal Microinstructions
- All control signals are explicitly encoded in parallel.
- Example:
| Reg1 → ALU | Mem[R2] → Reg3 | PC ← PC + 1 | - Pros: Faster (no decoding needed).
- Cons: Large memory (wastes space for unused signals).
2. Vertical Microinstructions
- Control signals are compressed (e.g., encoded fields for ALU operations).
- Example:
| Opcode: 10 (ADD) | RegSrc: R1 | RegDst: R2 | NextAddr: 5 | - Pros: Smaller memory (saves space).
- Cons: Slower (requires decoding).
TABLE: Horizontal vs. Vertical Microinstructions
| Feature | Horizontal | Vertical |
|---|---|---|
| Signal Encoding | All signals in parallel. | Compressed (encoded fields). |
| Speed | Faster (no decoding). | Slower (decoding overhead). |
| Memory Usage | High (wastes bits). | Low (efficient). |
| Complexity | Simple for CU. | Complex decoding logic. |
| Use Case | High-performance systems. | Cost-sensitive or complex ISAs. |
C. Microinstruction Sequencing
Microinstructions execute in a sequence, determined by:
- Sequential: Next address = current address + 1.
- Conditional: Branch based on flags (e.g.,
ZF=1for zero result). - Indirect: Jump to a microinstruction address stored in a register.
MERMAID: Microinstruction sequencing flowchart
flowchart TD
A["Start"] --> B["Fetch Microinstruction"]
B --> C{"Next Address?"}
C -->|"Sequential"| D["Addr = PC + 1"]
C -->|"Conditional"| E["Addr = Branch Table[ZF]"]
C -->|"Indirect"| F["Addr = Reg[R3]"]
D --> B
E --> B
F --> BCaption: How the CU fetches the next microinstruction.4. How Microprogramming Works: Step-by-Step
Example: Execute ADD R1, R2
Instruction Fetch:
- CU fetches
ADD R1, R2from memory. - Uses opcode
ADDto index into control memory (address0x10).
- CU fetches
Microinstruction Execution:
- Microinstruction 1 (Addr 0x10):
| Reg[R1] → ALU | Reg[R2] → ALU | ALUOp: ADD | NextAddr: 0x11 | - Microinstruction 2 (Addr 0x11):
| ALUOut → Reg[R3] | PC ← PC + 1 | NextAddr: 0x12 | - Microinstruction 3 (Addr 0x12):
| Halt | NextAddr: 0x10 (loop for next instruction) |
- Microinstruction 1 (Addr 0x10):
MERMAID: Microprogrammed ADD execution
sequenceDiagram
participant CU as Control Unit
participant ALU as ALU
participant Reg as Register File
CU->>Reg: Load R1, R2
Reg-->>ALU: Data A, B
ALU-->>CU: Result
CU->>Reg: Store Result in R3
CU->>CU: Increment PCCaption: Microprogrammed ADD execution flow.
5. Why Is Microprogrammed Control Slower?
| Factor | Hardwired CU | Microprogrammed CU |
|---|---|---|
| Latency | Direct signal paths (1-2 cycles). | Fetches microinstructions (extra cycle). |
| Pipeline Stalls | Rare (simple logic). | Common (sequencing overhead). |
| Parallelism | Full parallel control signals. | Sequential microinstruction fetch. |
| Real-World Impact | Used in RISC (e.g., MIPS). | Used in CISC (e.g., Intel Pentium). |
Example: eSewa Transaction Validation
- Scenario: When you pay a bill via eSewa, the system validates your transaction in microseconds.
- How Microprogramming Helps:
- The payment processor’s CU uses microcode to:
- Check account balance (microinstruction sequence for memory access).
- Deduct amount (ALU operations encoded in microinstructions).
- Update database (I/O control signals).
- Why not hardwired?
- eSewa’s system must handle multiple payment methods (Khalti, bank transfer). Microcode allows easy updates without hardware changes.
- The payment processor’s CU uses microcode to:
6. Booth’s Algorithm and Microprogramming
(Note: While Booth’s algorithm is in Unit 4, it’s often tested with microprogramming. Here’s how it connects.)
Booth’s Multiplication: Microprogrammed Steps
- Initialize:
- Load multiplicand (
M), multiplier (Q), and result registers (A,Q).
- Load multiplicand (
- Microinstruction Loop:
- Check last two bits of Q (
Q₀Q₋₁):01: SubtractMfromA, shift right.10: AddMtoA, shift right.00or11: Just shift right.
- Check last two bits of Q (
- Terminate: Repeat until all bits of
Qare processed.
MERMAID: Booth’s algorithm state diagram
stateDiagram-v2
[*] --> CheckBits
CheckBits --> Q0Q-1_01: "Q₀Q₋₁ = 01"
CheckBits --> Q0Q-1_10: "Q₀Q₋₁ = 10"
CheckBits --> Shift: "Q₀Q₋₁ = 00 or 11"
Q0Q-1_01 --> Subtract: "A = A - M"
Q0Q-1_10 --> Add: "A = A + M"
Subtract --> Shift
Add --> Shift
Shift --> CheckBitsCaption: Microprogrammed Booth’s multiplication states.Worked Example: Multiply 1101 × 1011
| Step | Q (Multiplier) | Q₀Q₋₁ | Action | A (Partial Product) |
|---|---|---|---|---|
| 1 | 1011 | 11 | Shift right | 0000 |
| 2 | 0101 | 10 | Add M (0110) | 0110 |
| 3 | 0010 | 01 | Subtract M (0110) | 0000 |
| 4 | 0001 | 01 | Subtract M (0110) | 1010 (complement) |
| 5 | 0000 | 00 | Shift right | 1101 |
Final Product: 10001101 (binary) = 141 (decimal).
7. Real-World Applications
A. eSewa / Khalti (Payment Processing)
- Idea Used: Microprogrammed control for transaction validation.
- How:
- When you pay a bill, the server’s CPU uses microcode to:
- Verify your Khalti/eSewa ID (memory access microinstructions).
- Check balance (ALU operations for subtraction).
- Update database (I/O control signals for writing to SQL).
- Why Microprogramming?
- eSewa’s system must handle multiple banks and fintech partners. Microcode allows dynamic updates without hardware changes.
- When you pay a bill, the server’s CPU uses microcode to:
B. Ncell Billing System
- Idea Used: Microprogrammed SIM authentication.
- How:
- When you top-up via Ncell’s app, the billing server uses microcode to:
- Authenticate your SIM (cryptographic operations via microinstructions).
- Deduct credits (ALU operations for balance updates).
- Log the transaction (memory write microinstructions).
- Advantage: If Ncell adds a new prepaid plan, they only update the microcode, not the hardware.
- When you top-up via Ncell’s app, the billing server uses microcode to:
C. Daraz Order Fulfillment (Queue Management)
- Idea Used: Microprogrammed priority scheduling.
- How:
- Daraz’s order processing system uses microcode to:
- Fetch orders from a queue (memory read).
- Check priority (conditional branches in microinstructions).
- Route to warehouse/shipper (I/O control signals).
- Example Trace:
sequenceDiagram participant CU as Control Unit participant Queue as Order Queue CU->>Queue: Read Order[1] Queue-->>CU: Priority=High CU->>CU: Branch to FastShipMicrocode CU->>Shipper: Send to Express
- Daraz’s order processing system uses microcode to:
8. Exam Tip: How to Score Full Marks
Do’s:
✅ Define clearly: Start with definitions (e.g., "A microprogrammed control unit replaces hardwired logic with a sequence of microinstructions stored in control memory."). ✅ Draw diagrams: Always include:
- Microinstruction format (horizontal/vertical).
- Sequencing flowchart (sequential/conditional).
- Booth’s algorithm states (if asked).
✅ Compare tables: Use a Hardwired vs. Microprogrammed table for marks.
✅ Worked examples: Show step-by-step microinstruction execution for
ADD/SUB/MUL. ✅ Real-world links: Mention eSewa/Khalti/Ncell in answers where applicable.
Don’ts:
❌ Don’t confuse horizontal/vertical: Horizontal has all signals in parallel; vertical has encoded fields. ❌ Don’t skip sequencing: Always explain how the next-address field works. ❌ Don’t assume hardwired is always better: Microprogramming is used in CISC processors (e.g., Intel). ❌ Don’t ignore Booth’s: If the question mentions multiplication, always show the algorithm steps.
Common Pitfalls in Exams
Mixing up microinstruction formats:
- Wrong: "Vertical microinstructions are faster."
- Correct: "Horizontal microinstructions are faster because they don’t need decoding."
Forgetting sequencing:
- Wrong: "Microinstructions execute randomly."
- Correct: "Sequencing is controlled by the next-address field (sequential/conditional/indirect)."
Ignoring real-world examples:
- Wrong: "Microprogramming is only theoretical."
- Correct: "eSewa uses microprogrammed control for transaction validation."
Sample Exam Answer (6 Marks)
Question: Explain the working of a microprogrammed control unit. Differentiate between horizontal and vertical microinstructions.
Model Answer: A microprogrammed control unit (CU) replaces hardwired logic with a sequence of microinstructions stored in control memory. Each microinstruction encodes the control signals needed to execute a single step of an instruction (e.g., "load register," "enable ALU").
Working Steps:
- Instruction Fetch: The CU fetches an instruction (e.g.,
ADD R1, R2) and uses its opcode to index into control memory. - Microinstruction Execution:
- The first microinstruction loads operands from registers into the ALU.
- Subsequent microinstructions perform the operation (e.g.,
ADD) and store the result.
- Sequencing: The next-address field determines the next microinstruction (sequential, conditional, or indirect).
- Termination: The last microinstruction updates the PC and halts until the next instruction.
Horizontal vs. Vertical Microinstructions
| Feature | Horizontal | Vertical |
|---|---|---|
| Signal Encoding | All control signals explicitly listed. | Compressed (encoded fields). |
| Example | `Reg1→ALU | Mem→Reg2 |
| Speed | Faster (no decoding). | Slower (decoding overhead). |
| Memory Usage | High (wastes bits). | Low (efficient). |
| Use Case | High-performance systems (e.g., supercomputers). | Complex ISAs (e.g., x86). |
Real-World Link:
Ncell’s billing server uses microprogrammed control to authenticate SIMs and process top-ups. Vertical microinstructions are used here for memory efficiency, while horizontal microinstructions could speed up critical paths like fraud detection.
Based on the PU BE Computer (PU) syllabus for Computer Architecture, unit 5.
Discussion
Loading…