4.1.8Computer Architecture (Deep)

Memory addressing modes — immediate, register, direct, indirect, indexed

2,060 words9 min readdifficulty · medium6 backlinks

WHY do addressing modes exist at all?

The central object every mode produces is the Effective Address (EA): the final memory address from which the operand is fetched (or written).

Operand=Memory[EA](except when no memory access is needed)\text{Operand} = \text{Memory}[\text{EA}] \quad \text{(except when no memory access is needed)}


The five modes — WHAT each one means

Figure — Memory addressing modes — immediate, register, direct, indirect, indexed

HOW the CPU executes each mode (step by step)

Take memory: M[100]=200, M[200]=350, M[204]=999, register R2=4, A=100.


Forecast-then-Verify (do this before reading the answer)


Common mistakes (Steel-man → Fix)


Recall Feynman: explain to a 12-year-old

Imagine a treasure hunt. An addressing mode is the clue type on each card.

  • Immediate: the card says "your treasure is the number 5" — the prize is written on the card.
  • Register: "look in your pocket #2" — quick, it's on you.
  • Direct: "go to house number 100" — the address is written plainly.
  • Indirect: "go to house 100, read the note inside, it tells you the real house" — two trips.
  • Indexed: "start at house 100, then walk forward as many houses as your counter says" — perfect for checking a whole street one by one (an array!).

Flashcards

What is an effective address (EA)?
The final memory address of an operand, computed by the CPU from the instruction bits according to the addressing mode.
Immediate mode — where is the operand and how many memory accesses?
Inside the instruction word itself; 0 operand memory accesses.
Register mode operand location?
In a CPU register R[i]R[i]; 0 memory accesses (fastest for memory bus).
Direct mode EA formula?
EA=A\text{EA}=A (the literal address in the instruction); operand =M[A]=M[A], 1 access.
Indirect mode EA and operand?
EA=M[A]\text{EA}=M[A], operand =M[M[A]]=M[M[A]]; 2 memory accesses; used for pointers.
Indexed mode EA formula?
EA=A+R[i]\text{EA}=A+R[i] (base + index register); operand =M[A+R[i]]=M[A+R[i]], 1 access.
Which mode is best for arrays and why?
Indexed — increment the index register in a loop to reuse the same instruction for each element.
Which mode is best for pointers / linked lists?
Indirect — the instruction holds the address of the address.
Key difference indirect vs indexed?
Indirect does an extra MEMORY read (M[A]M[A], 2 accesses); indexed does an ADDITION (A+R[i]A+R[i], 1 access).
Memory access count to fetch operand for each mode (Imm, Reg, Direct, Indirect, Indexed)?
0, 0, 1, 2, 1.
Why use immediate mode?
To supply constants with zero extra memory access (operand pre-fetched with the instruction).

Connections

Concept Map

rule computes

type

type

type

type

type

operand in instruction, 0 access

operand in R i, 0 access

EA = A, 1 access

EA = M A, 2 accesses

EA = A + R i, 1 access

used for

used for

used for

used for

used for

Addressing mode

Effective Address EA

Immediate

Register

Direct absolute

Indirect pointer

Indexed

Memory access to fetch operand

Constants

Fast temporaries

Global variables

Pointers, linked lists

Arrays and loops

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, jab CPU koi instruction chalata hai jaise ADD R1, X, toh sabse pehle usko pata karna padta hai ki operand X hai kahan. Yeh "kahan dhoondhna hai" ka rule hi addressing mode kehlata hai. Final jo asli memory location nikalti hai usko Effective Address (EA) bolte hain. Yahi poora khel hai.

Paanch main modes hain. Immediate matlab number instruction ke andar hi likha hai (jaise #5) — zero memory access, sabse fast for constants. Register matlab operand kisi register mein hai (R2 vagairah) — bhi bahut fast, kyunki register CPU ke andar hota hai. Direct matlab instruction mein seedha address likha hai: EA = A, ek memory access. Indirect thoda tricky — instruction jo address deta hai wahan asli address rakha hota hai, yaani pointer: EA = M[A], isliye do memory access lagte hain (slow). Indexed arrays ke liye perfect: EA = A + R[i], base address mein index register add kar dete hain, sirf ek memory access (plus ek chhoti si ALU addition).

Sabse common galti: students indirect aur indexed ko mix kar dete hain. Yaad rakho — indirect mein extra memory read hota hai (M[A]), indexed mein sirf addition hota hai (A + R[i]). Isiliye indirect = 2 memory access, indexed = 1 memory access. Doosri galti: socht lena ki immediate bhi memory se padhta hai — nahi! Immediate ka data instruction ke saath hi aa chuka hota hai, zero extra access.

Yeh kyun important hai? Kyunki real programs mein loops aur arrays hote hain. Agar indexed mode na ho toh har array element ke liye alag instruction likhni padti — bekaar. Aur pointers/linked lists ke liye indirect chahiye. 80/20 funda: bas EA ka formula aur memory-access count yaad rakho (0,0,1,2,1), baaki sab samajh aa jayega.

Go deeper — visual, from zero

Test yourself — Computer Architecture (Deep)

Connections