5.1.3 · D2Instruction Set Architecture (ISA)

Visual walkthrough — Addressing modes

2,524 words11 min readBack to topic

We only need three ideas, and we will draw each before using it:

  • a memory cell (a numbered box that holds a number),
  • a register (a super-fast box inside the CPU),
  • an instruction (a strip of bits split into a what-to-do part and a where part).

Everything below is just: how do we turn the "where" part into a real box?


Step 1 — What memory and a register even are

WHAT: we drew memory as numbered boxes and a register as one box. WHY: every addressing mode is a sentence like "start from , maybe add , maybe follow the arrow." If you can see the boxes and arrows, the formula writes itself. PICTURE: below, addresses run down the left; contents sit inside; the register R1 floats to the side holding .

Figure — Addressing modes

We use the exact numbers from the parent note's table so every example lands on a real box: , , , , and , , .


Step 2 — The goal: EA is a function, draw its inputs

WHAT: we named the machine and its three possible inputs. WHY: every mode is just a different wiring of these same three inputs into one output address. From now on, each mode's formula below is literally " with some inputs ignored" — Direct is , Register-indirect is , Displacement is , PC-relative is . Watch reappear in every step. PICTURE: three clue-arrows (, , ) feed a funnel labelled ; out drops a single address, which points at one memory box.

Figure — Addressing modes

Step 3 — The zero-arrow modes: Immediate & Register

WHAT: two modes that never open a memory box — here is not even called, because no address is needed. WHY start here? Because they are the base case: they use an input directly with zero arrows to follow. Every later mode is "these, but then take one or more steps into memory." PICTURE: on the left the instruction's box is the value (a self-loop, no travel). On the right an arrow reaches into the CPU register and stops there.

Figure — Addressing modes

Step 4 — One arrow: Direct mode

WHAT: we treat the instruction's as an address and open exactly one box — the funnel passes straight through. WHY this rule? It's the simplest way to point at a specific location. Cost: must be wide enough to name any box in memory. PICTURE: LOAD 100. One yellow arrow leaves , lands on box , and we read .

Figure — Addressing modes


Step 5 — One arrow via a register: Register-indirect

WHAT: the register's contents are the effective address; ignores and and returns . WHY a distinct mode? This is how you follow a pointer that lives in a register (e.g. a this-pointer, or the top of a stack). It is the cheapest way to reach data whose address is only known at run time — one arrow, not two. PICTURE: LOAD (R1), . A pink arrow leaves register R1, lands directly on box , and we read .

Figure — Addressing modes


Step 6 — Two arrows: Indirect mode (follow a pointer in memory)

WHAT: we opened box , found an address inside, then opened that box. WHY need a second arrow? So the instruction can point at data whose pointer lives in memory — following linked lists, chasing pointers. Price: an extra memory read every time. PICTURE: LOAD (100). Arrow ① hits box and finds ; arrow ② hops from there to box and reads .

Figure — Addressing modes


Step 7 — Adding two clues: Displacement (the workhorse)

WHAT: we added a register's contents to the instruction's constant before opening a box — now uses both and . WHY add, not just use one? Because arrays and structs live at a run-time base , but the element you want (offset ) is a fixed, small number known at compile time. Addition marries the run-time start to the compile-time step — that's why array[3] is cheap. PICTURE: LOAD 3(R1), . Draw the base arrow to , then step down the boxes to , and read .

Figure — Addressing modes


Step 8 — Using the PC as the base: PC-relative

WHAT: we used the PC itself as the base and added a signed offset; here uses and . WHY offsets, not absolute targets? Because the program might be loaded anywhere in memory. "Jump forward 6" stays correct no matter where the code sits; "jump to 206" would break if loaded elsewhere. This is position independence. PICTURE: BRANCH +6. A yellow arrow of length from the PC-reference marker lands on the target box.

Figure — Addressing modes


Step 9 — Modes with a side effect: Auto-increment / decrement

WHAT: register-indirect (Step 5), plus the register silently advances (or retreats) by . WHY bake stepping in? Streaming through an array or pushing/popping a stack needs "read, then move pointer" every iteration. Folding the move into the access removes an entire instruction from the loop — that's while(*p++). PICTURE: LOAD (R1)+, , . Read box ; then the R1 label slides from to (dashed arrow), ready for the next read.

Figure — Addressing modes


The one-picture summary

Everything above is one funnel fed by , followed by zero, one, or two arrows into memory. Read the modes as a family by how many arrows they follow:

Figure — Addressing modes

no

yes

A alone

register holds address

follow pointer in memory

base plus offset

PC plus distance

register pointer plus step

instruction field A and maybe R

open memory at all

Immediate or Register - 0 access

how is EA built

Direct EA = A - 1 access

Register-indirect EA = R - 1 access

Indirect EA = M of A - 2 access

Displacement EA = A plus R - 1 access

PC-relative EA = PC plus A - 1 access

Auto inc or dec - 1 access

Recall Feynman: the whole walkthrough in plain words

Memory is a street of numbered houses; a register is a tiny house you keep in your pocket. An instruction hands you a scrap of paper with a number on it. The addressing mode is just what the scrap means: "The gold is this number" (immediate — no walking). "It's in your pocket house" (register — no walking). "Go to house " (direct — one walk). "Your pocket note IS a house number — go straight there" (register-indirect — one walk). "House has a note with another address; go there" (memory-indirect — two walks). "Start at your pocket-house address, walk more doors" (displacement — one walk, and this is the one you'll use constantly for arrays). "Walk doors from where you're standing right now — measured from the next step you were about to take" (PC-relative — works no matter where the street starts). "Read your pocket-house door, then automatically nudge your pocket note to the next door" (auto-increment — perfect for reading a whole array). Count the walks into the street and you know the cost. That's the entire subject.

Recall Quick self-check

LOAD (100) with , — operand? ::: (memory-indirect: , then ) LOAD (R1) with , — operand? ::: (register-indirect: , one access) LOAD 3(R1) with — EA? ::: BRANCH +6 measured from — target? ::: Displacement with becomes which mode? ::: Register-indirect ()


See also: Addressing modes · Instruction Format · Registers and Register File · Memory Hierarchy · Pointers and Arrays · Stack and Subroutines · RISC vs CISC