Addressing modes are the different ways in which a CPU identifies the location of operands (data) required for an instruction.
An operand may be located:
Addressing modes give flexibility to the programmer and allow the instruction set to express a wide variety of operations.
Below are the most widely used addressing modes across architectures like MIPS, ARM, x86, RISC-V etc.
The operand is directly specified inside the instruction.
ADD R1, R2, #5 ; R1 = R2 + 5
The operand is located in a register.
ADD R1, R2, R3 ; R1 = R2 + R3
The instruction directly contains the memory address of the operand.
LOAD R1, 5000 ; R1 = Mem[5000]
The instruction specifies a register (or memory location) that contains the address of the operand.
LOAD R1, (R2) ; R1 = Mem[ R2 ]
If R2 = 3000, it loads from Mem[3000].
The effective address is calculated by:
Base Address + Index Register
LOAD R1, 200(R2) ; R1 = Mem[200 + R2]
A constant offset is added to a base register.
LOAD R1, 4(R3) ; R1 = Mem[R3 + 4]
(Indexed and Base+Offset are very similar; RISC uses Base+Offset most.)
The effective address is calculated relative to the Program Counter (PC).
BEQ R1, R2, LABEL ; Jump to PC + offset
Address used for operand is taken from a register, and the register is automatically incremented or decremented.
LOAD R1, (R2)+ ; R1 = Mem[R2], then R2 = R2 + 1
PUSH (–R2) ; R2 = R2 – 1, then Mem[R2] = value
Operand address = register + constant displacement
Basically the same as base + offset, but used generally for:
LOAD R1, 8(RBP) ; Load local variable at offset 8
The instruction first accesses memory to get an address, then uses that address to get the operand.
LOAD R1, @(5000) ; R1 = Mem[ Mem[5000] ]
| Addressing Mode | Operand Location | Example | Usage |
|---|---|---|---|
| Immediate | In instruction | ADD R1, #5 | Constants |
| Register | Register | ADD R1, R2 | Fast ops |
| Direct | Memory address in instruction | LOAD R1, 5000 | Simple access |
| Indirect | Register holds address | LOAD R1, (R2) | Pointers |
| Indexed | Base + index | LOAD R1, 100(R3) | Arrays |
| Base + Offset | Register + offset | LOAD R1, 4(R2) | Structures, stack |
| PC-relative | PC + offset | BEQ label | Branching |
| Auto-inc/dec | Reg used then updated | LOAD R1, (R2)+ | Stacks |
| Memory Indirect | Mem contains address | LOAD R1, @(A) | Pointer chains |
Open this section to load past papers