Published by Patrick Mutisya · 14 days ago
In assembly language the addressing mode determines how the operand of an instruction is obtained. Understanding the different modes is essential for writing efficient low‑level code and for interpreting machine code generated by a compiler.
The table below summarises the most frequently used addressing modes in typical 8‑bit and 32‑bit architectures (e.g., 8085, 8086, ARM, MIPS).
| Mode | Syntax (example) | Description | Typical Use |
|---|---|---|---|
| Immediate | MO \cdot R0, #5 | The operand is a constant value encoded directly in the instruction. | Loading constants, setting flags. |
| Direct (Absolute) | LDA 0x3C00 | The address of the operand is given explicitly in the instruction. | Accessing fixed variables, I/O ports. |
| Register | ADD R1, R2 | Both source and destination are registers; no memory reference is needed. | Arithmetic, logical operations. |
| Register Indirect | LDR R0, [R1] | The register contains the memory address of the operand. | Pointer dereferencing, stack access. |
| Indexed | LDA 0x2000(R2) | Effective address = base address + index register. | Array element access. |
| Based‑Indexed with Displacement | LDR R0, [R1 + R2*4 + 8] | Effective address = base + (index × scale) + displacement. | Structure field access, complex array indexing. |
| Relative (PC‑relative) | BR label | Target address = current program counter + signed offset. | Branching, loops, function calls. |
| Stack‑relative | PUSH R3 / POP R4 | Implicitly uses the stack pointer as the address register. | Procedure call/return, local variable storage. |
For modes that involve a base, index, scale and displacement, the effective address (EA) is computed as:
\$\text{EA} = \text{Base} + (\text{Index} \times \text{Scale}) + \text{Displacement}\$
Where:
Assume an integer array int a[10]; stored starting at address 0x1000. To load a[i] into register R0 on a 32‑bit architecture that uses a base‑indexed mode:
; R1 holds the index i; R2 holds the base address of the array (0x1000)
LDR R0, [R2 + R1*4] ; scale = 4 because each int occupies 4 bytes
Here the effective address is calculated as \$\text{EA}=0x1000 + (i \times 4)\$ which points to the required element.
Consider the C structure:
struct Point {int x; // offset 0
int y; // offset 4
};
struct Point p;
If the address of p is in register R3, the field y can be loaded using a based‑indexed mode with displacement:
LDR R0, [R3 + 4] ; load p.yAddressing modes provide the bridge between the abstract operations of a program and the concrete locations of data in memory. Mastery of these modes enables you to:
Practice by translating small C snippets into assembly, paying particular attention to how each variable is accessed. This will reinforce the concepts and prepare you for the A‑Level examination.