# Addressing Modes, Hardwired vs Microprogrammed Control Unit & DMA I/O
Exam: GATE Computer Science & Information Technology (GATE CS)
Subject: Computer Organization & Architecture
Canonical URL: https://gateandnet.com/exams/gate-cs/computer-organization/addressing-modes-control-unit-and-dma

> Effective address computation for PC-relative and indexed modes, horizontal vs vertical microinstructions control store size, and DMA cycle-stealing CPU slowdown.

## 1. Machine Addressing Modes & Relocation

| Addressing Mode | Effective Address (EA) | Primary Compiler / OS Use Case |
| :--- | :--- | :--- |
| **Immediate** | Operand inside instruction | Constants (`MOV R1, #42`) |
| **Register Indirect** | $EA = [R_i]$ | Pointers in C (`*ptr`) |
| **Base + Displacement / Indexed** | $EA = [R_b] + \text{Offset}$ | Array indexing `A[i]` & struct fields |
| **PC-Relative** | $EA = \text{PC}_{\text{next}} + \text{Offset}$ | **Position-Independent Code (PIC)** & short branches |
| **Auto-Increment / Decrement** | $EA = [R_i];\; R_i \leftarrow R_i \pm d$ | Stack `PUSH` / `POP` & loop traversal |

> [!TRAP]
> **Classic GATE PC-Relative Trap:** If a 4-byte branch instruction sits at byte address $1000$ with signed offset $-16$, when the ALU computes the target, $\text{PC}$ already equals $1000 + 4 = 1004$. Thus Target $= 1004 + (-16) = 988$ (NOT $984$!).

## 2. Hardwired vs Microprogrammed Control Unit

- **Hardwired Control:** Combinational logic gates driven by state counter + IR opcode; fastest clock rate, used in **RISC** processors.
- **Microprogrammed Control:** Stores microinstructions in Control ROM.
  - **Horizontal Microprogramming:** 1 bit per control signal ($N$ signals = $N$ bits); maximum parallelism, zero decoder delay.
  - **Vertical Microprogramming:** Mutually exclusive micro-operations grouped into fields of $\lceil \log_2(m_i + 1) \rceil$ bits (+1 for `NO-OP`!).

## 3. Interrupts vs Direct Memory Access (DMA)

In **Cycle Stealing DMA**, if a device generates data at $R$ bytes/sec, transfers $w$ bytes per bus cycle, and each DMA bus steal stalls the CPU for $t_{\text{steal}}$ seconds:

$$
\%\text{ CPU Slowdown ( Bus Utilization )} = \frac{t_{\text{steal}}}{t_{\text{prep}}} \times 100\%, \quad t_{\text{prep}} = \frac{w}{R}
$$

## Solved Practice Questions & PYQs

### [GATE CS COA | MCQ]
A **4-byte** PC-relative branch instruction is stored in memory starting at byte address $2000$. If the signed displacement field inside the instruction equals $-24$, what is the **branch target byte address**?
**Correct Answer:** B
**Solution:** During instruction fetch, $\text{PC}$ increments to the next sequential instruction first: $\text{PC}_{\text{next}} = 2000 + 4 = 2004$. Adding the signed offset gives Target $= 2004 + (-24) = \mathbf{1980}$.

### [UGC NET / GATE COA | MCQ]
Which machine addressing mode is best suited for writing **relocatable / position-independent code** at runtime?
**Correct Answer:** C
**Solution:** **PC-Relative** and **Base-Register** addressing compute effective addresses relative to `PC` or a base register, allowing the entire program segment to be loaded anywhere in physical RAM without patching instruction addresses.
