Addressing Modes in Computer Architecture
Addressing modes refer to the way the operand (data) of an instruction is specified. The technique used to determine the **Effective Address (EA)** of an operand determines the speed and flexibility of the instruction execution.
Commonly Used Addressing Modes
Different architectures (like x86 or ARM) use various modes to balance instruction length and power.
- **Implied/Implicit Mode:** The operand is specified implicitly in the definition of the instruction. (e.g., CLC - Clear Carry bit).
- **Immediate Mode:** The operand is specified in the instruction itself rather than an address. (e.g., MOV R1, #20).
- **Register Mode:** The operand is stored in a register, and the register name is given in the instruction.
- **Direct (Absolute) Mode:** The instruction contains the actual memory address of the operand.
- **Indirect Mode:** The instruction gives an address that contains the *actual* address of the operand.
Comparison of Primary Modes
| Mode | Effective Address (EA) | Advantage | Disadvantage |
|---|---|---|---|
| Immediate | Operand is part of instruction | Fastest (No memory ref) | Limited operand size |
| Direct | EA = Address Field | Simple to implement | Limited address space |
| Register | EA = Register | Very fast access | Limited number of registers |
| Indirect | EA = [Address Field] | Large address space | Slow (Multiple memory refs) |
Displacement Addressing Modes
These modes combine the contents of a register with an address field to find the operand. This is crucial for arrays and data structures.
- **Relative Addressing:** EA = PC + Address. Used for JUMP instructions.
- **Indexed Addressing:** EA = Index Register + Constant. Used for accessing array elements.
- **Base Register Addressing:** EA = Base Register + Displacement. Used for segmenting memory.
Example Scenarios
TEXT
Immediate: ADD R1, #5 ; R1 = R1 + 5
Direct: LOAD R1, 1000 ; R1 = Contents at Mem[1000]
Register: ADD R1, R2 ; R1 = R1 + R2
Common Mistakes to Avoid
- Confusing the address with the data stored at that address.
- Forgetting that Indirect addressing requires two memory accesses.
- Assuming Immediate mode can be used for large data values.
- Miscalculating the PC-relative offset during branch instructions.
Advanced Concepts
- Auto-increment and Auto-decrement modes
- Stack Addressing Mode
- Instruction Set Orthogonality
- Effective Address Calculation in Paging systems
- Memory-mapped I/O addressing
Practice Exercises
- Given R1=200 and Mem[200]=50, find the operand for 'LOAD R2, (R1)' using indirect mode.
- Why is Register addressing faster than Direct addressing?
- Calculate the EA for an Indexed mode instruction where the base is 500 and index is 20.
- Explain the use of Relative addressing in position-independent code.
Conclusion
Addressing modes provide the flexibility needed to write efficient programs. While simple modes like Immediate are fast, displacement modes are essential for handling complex data structures like arrays and objects.
Note: Note: Modern RISC processors limit the number of addressing modes to simplify the hardware and allow for better pipelining.
Codecrown