Home / Learn Chip Programming / Addressing Modes in Depth
Addressing Modes in Depth
Addressing modes are the different ways an instruction can name its data. They explain pointers, arrays and structs at machine level.
Theory in plain words
What it is
Immediate: the value is in the instruction. Register: in a register. Direct: at a fixed address. Indirect: a register holds the address. Indexed: base register plus offset. Auto increment: pointer moves after use.
Why we use it
The mode decides speed and code size. High level features (pointers, arrays, struct fields, stack variables, jumps) map to specific modes.
How it works
The CPU computes an effective address (EA) from the instruction fields and register contents, then reads or writes memory at EA.
Where it is used
- Reading assembly and compiler output
- Writing efficient drivers
- Understanding pointers
Try each mode
Indexed mode with base 8 and offset 4 reads address 12: exactly how arr[4] works when R1 points to the start of the array.
| C code | Mode used |
|---|---|
| x = 5; | immediate |
| x = y; (both in registers) | register |
| x = global_var; | direct / PC relative |
| x = *p; | indirect (register holds the pointer) |
| x = arr[i]; or p->field | indexed / base plus offset |
| *p++ = c; | auto increment |
| local variable | stack pointer plus offset |
| goto / function call | PC relative or absolute |
Quick quiz
1. Which mode matches *p in C?
A register holds the address of the data.
2. Which mode matches arr[i]?
Base address plus scaled index.
Common questions
Which mode matches *p in C?
Indirect. A register holds the address of the data.
Which mode matches arr[i]?
Indexed (base plus offset). Base address plus scaled index.