Skip to content
CurriculumLesson 36 · Architecture
Intermediate~16 min

Addressing Modes

The instruction says what to do; the addressing mode says where the operand is. Direct, indirect, relative, indexed, and paging each compute a different effective address.

In plain English

Addressing modes are different ways to tell the CPU where an ingredient is: in the bowl, in the fridge, or through a note.

By the end you will be able to

  • Explain the effective address.
  • Compute direct, indirect, relative, indexed, and paging addresses.
  • Know the cost of indirect addressing.
  • Match addressing modes to arrays and position-independent code.
01

Direct and indirect

In direct addressing, the instruction contains the operand address. The CPU reads that address once. In indirect addressing, the instruction contains an address that points to the operand address. The CPU must read memory once to get the effective address and again to get the operand, so indirect addressing costs an extra memory access.

lesson-36.osOS
direct:    EA = address_in_instruction
indirect:  EA = memory[address_in_instruction]
           operand = memory[EA]
02

Relative and indexed

Relative addressing adds a signed offset to the program counter. It supports position-independent code because the offset is relative to the current instruction. Indexed addressing adds an index register to a base address, which is how arrays are traversed: the base points to the array and the index selects the element.

lesson-36.osOS
relative: EA = PC + offset
indexed:  EA = base + index
array[i]: base = &array[0], index = i * element_size
03

Paging addressing

Paging addressing translates a virtual address through the page table before the memory access. The CPU splits the address into a virtual page number and an offset, looks up the frame, and forms the physical address. If the page is not present, the access raises a page fault instead of completing.

lesson-36.osOS
vpn    = vaddr / page_size
offset = vaddr % page_size
frame  = page_table[vpn]
paddr  = frame * page_size + offset

Key takeaways

  • The effective address is the final address used by the CPU.
  • Direct uses the address in the instruction.
  • Indirect uses a pointer and costs an extra memory read.
  • Relative supports position-independent code.
  • Indexed supports arrays; paging translates through a page table.

Common pitfalls

  • Confusing the address in the instruction with the operand.
  • Forgetting the extra memory access for indirect addressing.
  • Mixing up relative and indexed addressing.

Kernel notes

  • Compute the effective address for each mode.
  • Know which mode supports arrays and which supports position independence.
  • Know why indirect addressing is slower.

Quick check

0 / 2 answered

1. Which addressing mode uses a pointer to the operand address?

2. Which mode adds an index register to a base address?