Suppose a friend asks you to "bring the book". You could hand them the book directly. You could tell them the shelf number where it is. You could give them a note saying "the shelf number is written on the fridge". Or you could say "it is the third book after the one I showed you". All of these lead to the same book, in different ways.
An instruction faces the same choice when it names an operand. The operand field may hold the value itself, a register number, a memory address, the address of an address, or an offset from some register. The rule that says how to interpret the operand field is called the addressing mode.
An addressing mode is the rule an instruction uses to specify the location of its operand, that is, how the operand field (together with registers) is used to obtain the operand or its effective address.
The effective address (EA) is the actual memory address where the operand is found (or where the result is stored), after the addressing mode has been applied.
In Instruction Format & Instruction Cycle we saw that the operand-fetch step computes the effective address. This chapter explains every common way of doing that, why each mode exists, and how to solve the numerical questions that exams love.
Why Have Several Addressing Modes?
One mode would be simpler for the hardware, so why bother with many?
Short instructions with large reach. A 32-bit instruction cannot hold a full 32- or 64-bit address. Modes that use a register (which can hold a full address) plus a small offset solve this.
Matching programming constructs. Constants, local variables, pointers, arrays, struct fields and loops each map naturally onto a particular mode. Fewer instructions are needed when the mode does the address arithmetic.
Relocatable code. Programs and libraries are loaded at different addresses each time. Modes relative to the PC or a base register let the same code run anywhere.
Speed. Register operands need no memory access at all.
The notation below: A = contents of the address field of the instruction, R = a register named in the instruction, (X) = contents of register or memory location X, EA = effective address.
The Addressing Modes
1. Implied (Implicit) Mode
The operand is implied by the opcode itself, so no operand field is needed. Examples: "complement the accumulator" (the accumulator is implied), "clear carry flag", and zero-address stack instructions like ADD, which implicitly use the top of the stack.
2. Immediate Mode
The operand field holds the operand value itself.
MOV R1, #25 ; R1 ← 25 Operand = A (no memory access for data)
+--------+------+-------------+
| opcode | R1 | 25 | ← the data is inside the instruction
+--------+------+-------------+
Use: constants and initial values. Fast, because no extra memory reference is needed. Limitation: the constant is limited by the field size (for example 12 bits signed in RISC-V's addi, i.e. −2048 to 2047).
3. Register Mode
The operand is in a register; the field holds the register number.
ADD R1, R2 ; R1 ← R1 + R2 Operand = (R)
Use: frequently used variables and temporaries. Fastest mode, and register fields are short (5 bits for 32 registers). Limitation: only a small number of registers exist.
4. Direct (Absolute) Mode
The address field holds the effective address of the operand.
LOAD R1, 600 ; R1 ← M[600] EA = A
Use: global and static variables at fixed addresses. One memory access for the operand. Limitation: the address space reachable is limited by the size of the address field.
5. Indirect (Memory Indirect) Mode
The address field holds the address of a memory word that contains the effective address.
LOAD R1, @600 ; R1 ← M[M[600]] EA = (A)
instruction memory
+-----------+ +-----------+
| LOAD 600 |------->| 600: 720 |----+
+-----------+ +-----------+ |
| 720: 230 |<---+ operand = 230
+-----------+
Use: pointers stored in memory, jump tables, reaching a large address space through a short field. Cost: two memory accesses to get the operand (one for the address, one for the data).
6. Register Indirect Mode
The register holds the effective address.
LOAD R1, (R2) ; R1 ← M[R2] EA = (R)
Use: pointers. x = *p; with p in a register compiles to exactly this. Only one memory access for the operand (the address is already in the CPU), and the register can hold a full-width address.
7. Autoincrement and Autodecrement Modes
Like register indirect, but the register is also updated automatically, so it steps through consecutive memory locations:
LOAD R1, (R2)+ ; R1 ← M[R2], then R2 ← R2 + d (post-increment)
LOAD R1, −(R2) ; R2 ← R2 − d, then R1 ← M[R2] (pre-decrement)
Here d is the operand size (1 for a word-addressable machine, or 1, 2, 4, 8 bytes on a byte-addressable one). The usual convention (from the PDP-11 and the 68000) is increment after the access and decrement before the access. Together they implement a stack: −(SP) pushes and (SP)+ pops. Use: walking through arrays and strings, stack push/pop. ARM provides the same idea as pre-indexed and post-indexed addressing with write-back, for example LDR r0, [r1], #4 (load, then add 4 to r1).
8. Displacement Modes: EA = A + (R)
Three important modes share the same arithmetic, an address field plus a register, and differ only in which register is used and what each part means.
(a) Relative (PC-Relative) Mode
EA = (PC) + A A is a signed offset
Use: branches and position-independent code. A loop that jumps back 64 bytes jumps back 64 bytes wherever the program is loaded, so the code works at any address. Offsets are small because branch targets are usually nearby, so few bits are needed.
Which PC value is used? In the textbook model the PC has already been incremented during fetch, so EA = (address of the next instruction) + A. Real ISAs fix their own rule: RISC-V branch offsets are measured from the address of the branch instruction itself; x86 measures from the next instruction. Always use the convention the question states.
(b) Indexed Mode
EA = A + (XR) A = start address of an array, XR = index register
Use: arrays. A is fixed in the instruction (the array's base address), and changing the index register selects different elements.
(c) Base Register Mode
EA = (BR) + A BR = base register holding an address, A = displacement
Use: relocation and data structures. The base register holds the start of a segment, a stack frame or a struct; the small displacement picks a field inside it. Moving the program or data only requires changing the base register. The struct access p->y (p in a register, y at offset 4) and local variables at fixed offsets from the stack/frame pointer are base-register accesses.
Indexed vs base: in indexed mode the instruction holds the (large) base address and the register holds the (changing) index; in base mode the register holds the (full) base address and the instruction holds a (small) displacement. In hardware both are "add a field to a register".
(d) Base + Index (Scaled) Mode
Some CISC processors combine everything: EA = base + index × scale + displacement, with scale = 1, 2, 4 or 8. This lets a[i] for an array of 4-byte ints be accessed in one instruction, as we will see in real x86 code below.
9. Stack Addressing
The operand is on top of the stack, addressed implicitly through the stack pointer (SP). PUSH, POP, CALL and RET use it. It is really register indirect with autoincrement/autodecrement on SP.
All Modes at a Glance
Mode | Operand / EA | Memory accesses to get operand* | Typical use |
|---|---|---|---|
Implied | Implied by opcode | 0 | Accumulator / flag / stack ops |
Immediate | Operand = A | 0 | Constants |
Register | Operand = (R) | 0 | Variables in registers |
Direct | EA = A | 1 | Global / static variables |
Indirect | EA = (A) | 2 | Pointers in memory |
Register indirect | EA = (R) | 1 | Pointers in registers |
Autoincrement / decrement | EA = (R), then R updated (or R updated first) | 1 | Array traversal, stacks |
PC-relative | EA = (PC) + A | 1 | Branches, position-independent code |
Indexed | EA = A + (XR) | 1 | Arrays |
Base register | EA = (BR) + A | 1 | Relocation, struct fields, stack frames |
* Not counting the instruction fetch itself. Note that immediate data is part of the instruction, so it arrives with the fetch.
Worked Example: One Instruction, Nine Modes
This is the classic exam problem. Work through it carefully: it tests every mode at once.
Problem. A two-word instruction "load to AC" is stored at addresses 300 and 301. The first word holds the opcode and mode; the second word (at 301) holds the address field, whose value is 600. The next instruction is at 302. Register R1 = 500 and index register XR = 150. Memory contains:
Address | Contents |
|---|---|
499 | 620 |
500 | 850 |
600 | 720 |
720 | 230 |
750 | 910 |
902 | 440 |
300 | LOAD to AC | mode |
301 | 600 | ← address field A
302 | next instruction | ← PC = 302 after the fetch
For each addressing mode, find the effective address and the value loaded into AC. (R1 is the register used by the register-based modes.)
Solution.
Mode | Calculation | EA | AC gets |
|---|---|---|---|
Immediate | Operand is the address field itself, stored at 301 | 301 | 600 |
Direct | EA = A | 600 | M[600] = 720 |
Indirect | EA = M[A] = M[600] | 720 | M[720] = 230 |
Relative | EA = PC + A = 302 + 600 | 902 | M[902] = 440 |
Indexed | EA = A + XR = 600 + 150 | 750 | M[750] = 910 |
Register | Operand is in R1 | none | 500 |
Register indirect | EA = R1 | 500 | M[500] = 850 |
Autoincrement | EA = R1 = 500, then R1 ← 501 | 500 | 850 |
Autodecrement | R1 ← 499 first, then EA = 499 | 499 | M[499] = 620 |
Points to notice:
For relative mode, use the updated PC (302), not 300 or 301. A two-word instruction increments the PC by 2.
Autoincrement uses the old R1 (500) and only then increments. Autodecrement decrements first, so it uses 499.
For immediate mode, some books say the "EA" is 301 (where the operand lives, inside the instruction) and others say there is no EA. The value loaded, 600, is the same either way.
Worked Example: Computing a Branch Offset
Problem. A 4-byte PC-relative branch instruction is stored at byte address 1000. It must jump to address 940. The offset field is 16 bits, 2's complement, and is added to the PC after the PC has been incremented past the instruction. What offset is stored?
Solution. After fetching, PC = 1000 + 4 = 1004. Offset = target − PC = 940 − 1004 = −64. In 16-bit 2's complement, −64 is 1111 1111 1100 0000 = FFC016.
Check: 1004 + (−64) = 940. ✔ If the same question used the RISC-V convention (offset relative to the branch's own address), the offset would be 940 − 1000 = −60.
A second example: a 2-byte branch at 2000 jumping forward to 2100 under the textbook convention needs offset 2100 − 2002 = +98.
Addressing Modes in Real Code (x86-64)
To see that addressing modes are not just theory, here is a small C file compiled for x86-64 with GCC 15.2 (gcc -O1 -fcf-protection=none -c) and disassembled with objdump -d --no-show-raw-insn -M intel (blank lines removed). The -fcf-protection=none flag only stops Ubuntu's GCC from adding an endbr64 security marker at the start of every function, which would clutter the listing:
int counter; /* a global variable */
struct point { int x, y; };
int imm(void) { return 42; }
int glob(void) { return counter; }
int deref(int *p) { return *p; }
int field(struct point *p) { return p->y; }
int elem(int *a, long i) { return a[i]; }
void bump(int *a, long i, int v) { a[i] += v; }
Output (the first argument arrives in register rdi, the second in rsi, the third in edx; the result goes in eax):
0000000000000000 <imm>:
0: mov eax,0x2a
5: ret
0000000000000006 <glob>:
6: mov eax,DWORD PTR [rip+0x0] # c <glob+0x6>
c: ret
000000000000000d <deref>:
d: mov eax,DWORD PTR [rdi]
f: ret
0000000000000010 <field>:
10: mov eax,DWORD PTR [rdi+0x4]
13: ret
0000000000000014 <elem>:
14: mov eax,DWORD PTR [rdi+rsi*4]
17: ret
0000000000000018 <bump>:
18: add DWORD PTR [rdi+rsi*4],edx
1b: ret
C code | Instruction | Addressing mode |
|---|---|---|
|
| Immediate (0x2a = 42) for the source; register for the destination |
|
| PC-relative (x86 calls the PC |
|
| Register indirect |
|
| Base + displacement (y is 4 bytes into the struct) |
|
| Base + scaled index (4 = sizeof(int)) |
|
| Scaled index as the destination: read, add and write memory in one instruction |
On a load-store RISC machine such as RISC-V, loads and stores have just one memory addressing mode, base + 12-bit signed displacement (lw x5, 8(x6)), and arithmetic uses only registers and immediates. Something like a[i] += v needs separate shift, add, load, add and store instructions. That design choice is the heart of Instruction Set Architecture: RISC vs CISC.
Which Mode for Which Job?
Programming construct | Natural addressing mode |
|---|---|
Constant ( | Immediate |
Local variable held in a register | Register |
Global / static variable | Direct (or PC-relative in position-independent code) |
Pointer dereference ( | Register indirect |
Pointer stored in memory ( | Memory indirect |
Array element ( | Indexed / scaled index |
Struct field, local variable in stack frame | Base + displacement |
Walking through an array ( | Autoincrement |
Stack push / pop | Autodecrement / autoincrement on SP |
Branches, relocatable code | PC-relative |
Worked Example: Counting Memory Cycles
Problem. Consider the two-word instruction ADD X[R0], @Y, meaning: add the operand at memory-indirect address Y to the operand at indexed address X + R0, and store the result back in the first operand. How many memory cycles does it need (a) for the whole instruction, (b) excluding instruction fetch?
Solution.
Fetch the instruction: 2 words → 2.
First operand, indexed: EA = X + R0, read M[EA] → 1.
Second operand, indirect: read M[Y] to get the address, then read the operand → 2.
Store the result at X + R0 → 1.
(a) 2 + 1 + 2 + 1 = 6. (b) Excluding fetch: 4.
Common Mistakes
Using the old PC in relative mode. In the textbook convention the PC has already moved past the whole instruction (including extra words) when the EA is computed.
Getting autoincrement/decrement order wrong. Post-increment uses the register first; pre-decrement updates first.
Confusing register indirect with memory indirect. Register indirect: 1 memory access (address is in a register). Memory indirect: 2 accesses.
Thinking immediate mode accesses memory for data. The operand arrives with the instruction fetch.
Mixing up indexed and base modes. Same arithmetic; the difference is which part holds the base address.
Forgetting to scale the index. On a byte-addressable machine, element i of an int array is at base + 4i, not base + i.
Writing a negative offset in the wrong width. −64 in 8 bits is 1100 0000, in 16 bits 1111 1111 1100 0000.
GATE and Interview Questions
Which addressing modes help make a program relocatable (position-independent)?
PC-relative mode (and base register mode). Addresses are computed relative to the PC or a base register, so the code works no matter where it is loaded.
Match: (1) array access, (2) pointer in a register, (3) constant, (4) branch to a nearby label. Options: immediate, indexed, register indirect, PC-relative.
(1) indexed, (2) register indirect, (3) immediate, (4) PC-relative.
Which mode needs the most memory accesses to obtain an operand: direct, register indirect or memory indirect?
Memory indirect: two accesses (one to read the address, one to read the operand). Direct and register indirect need one each.
A 2-word instruction at address 500 (word-addressable) has address field 25 in relative mode. What is the EA?
PC after fetch = 502, so EA = 502 + 25 = 527.
R1 = 2000 and memory word 2000 contains 3000. What does LOAD R2, (R1)+ do, assuming 4-byte words on a byte-addressable machine?
R2 ← M[2000] = 3000, then R1 ← 2004.
Why is immediate mode faster than direct mode?
The operand is part of the instruction, so no extra memory access is needed after the fetch. Direct mode needs one more memory access to read the operand.
Why does RISC-V provide only one addressing mode for loads and stores?
Base + displacement covers register indirect (displacement 0), struct fields, stack variables and, with a separate address calculation, arrays. A single simple mode keeps the decoder and pipeline simple and fast; more complex address arithmetic is done with ordinary instructions.
What is the difference between indexed and base-register addressing?
Both compute EA = field + register. In indexed mode the instruction holds the base address of a data structure and the register holds an index that changes. In base mode the register holds a base address (for example, of a segment or struct) and the instruction holds a small displacement within it.
Summary
An addressing mode says how to find the operand; the effective address is where the operand actually is.
Immediate (operand in instruction) and register (operand in register) need no data memory access.
Direct: EA = A. Indirect: EA = M[A] (2 accesses). Register indirect: EA = (R).
Autoincrement uses then increments; autodecrement decrements then uses. Together they implement stacks.
Displacement modes compute A + register: PC-relative (branches, relocatable code), indexed (arrays), base (relocation, structs, stack frames).
For relative mode, use the PC value after fetch unless the ISA says otherwise; RISC-V measures from the branch itself.
CISC machines like x86 offer rich modes (base + index × scale + displacement, memory destinations); RISC machines keep one simple load/store mode.
The operand field is only half the story; the addressing mode tells the CPU how to read it.