5.1.3 · HinglishInstruction Set Architecture (ISA)

Addressing modes

2,036 words9 min readRead in English

5.1.3 · Hardware › Instruction Set Architecture (ISA)


WHY addressing modes exist karte hain?

Teen pressures inhe shape karte hain:

  • WHY (flexibility): arrays ko index chahiye, pointers ko indirection chahiye, loops ko auto-increment chahiye.
  • WHY (compactness): chhote constants aur nearby data ko poora 32-bit address nahi chahiye.
  • WHY (speed): register operands sabse fast hote hain; smart modes instruction count reduce karte hain.

WHAT compute ho raha hai: Effective Address


HOW har mode kaam karta hai (EA rule scratch se derive karo)

Maan lo instruction mein ek field hai (ek address ya displacement) aur possibly ek register name . ka matlab hai "memory ka content par" aur ka matlab hai "register ka content".

WHY har rule waisa dikhta hai jaisa dikhta hai:

  • Immediate — constant instruction mein hi baked hota hai, isliye koi address chahiye nahi. Sabse fast, lekin value compile time par fix hoti hai aur field width se limited hoti hai.
  • Direct — address bits hi address hain. Simple, lekin itna wide hona chahiye ki kisi bhi location ko naam de sake.
  • Indirect ek pointer cell ko naam deta hai; CPU use read karta hai real address paane ke liye. Linked structures follow karna enable karta hai, lekin extra memory read ka cost lagta hai.
  • Displacement () — yeh workhorse mode hai. ek base hold karta hai (array/struct/stack frame ka start), ek chhota offset hai. Isliye array A[i] aur struct fields saste hote hain.
  • PC-relative — code ko position-independent banata hai: ek branch kitna jump karna hai store karta hai, koi absolute target nahi, toh program sahi se chalega chahe kahaan bhi load ho.
  • Auto inc/dec — pointer-stepping ko access mein bake kar deta hai, stacks ke liye perfect (push/pop) aur arrays mein streaming ke liye.
Figure — Addressing modes

Worked examples

Maan lo memory aur registers:

Address Contents Register Contents
100 500 R1 400
400 700 R2 3
500 800 PC 200
403 900

Common mistakes (steel-manned)


The 80/20 core


Flashcards

Ek addressing mode kya determine karta hai?
Woh rule jo compute karta hai ki operand kahan hai (uska effective address) instruction bits aur registers se.
Effective address (EA) define karo.
Operand ka final memory address jo addressing-mode rule apply hone ke baad milta hai.
Immediate mode: operand ke liye kitne memory accesses?
Zero — operand value instruction ke andar hi stored hoti hai.
Direct mode ke liye EA rule?
EA = A (address field hi address hai).
Indirect mode ke liye EA rule aur uska cost?
EA = M[A]; 2 memory accesses chahiye (pointer read karo, phir operand read karo).
Register-indirect aur memory-indirect mein difference?
Register-indirect: EA=(R), 1 access. Memory-indirect: EA=M[A], 2 accesses.
Displacement/based mode ke liye EA rule?
EA = A + (R): base register plus ek constant offset.
PC-relative mode branches ke liye kyun use hota hai?
Yeh ek distance/offset store karta hai (EA = PC + A), jo code ko position-independent/relocatable banata hai.
Stack push/pop aur array streaming ke liye kaunsa mode ideal hai?
Auto-increment / auto-decrement.
Kaun se do modes ~80% real instructions cover karte hain?
Register mode aur displacement (base+offset) mode.
LOAD 3(R1) mein jab (R1)=400 ho, EA kya hai?
403 (EA = 3 + 400).
Bahut saare complex addressing modes add karne ka trade-off?
Kam instructions lekin zyada complex decode/longer critical path (CISC vs RISC trade-off).

Recall Feynman: 12-saal ke bachche ko samjhao

Socho ek treasure map hai. Kabhi map kehta hai "gold RIGHT HERE hai" (immediate — jawab map par hi likha hai). Kabhi kehta hai "gold spot #100 par gada hai" (direct — 100 par jao aur khodo). Kabhi spot #100 par ek aur note hota hai jo kehta hai "actually yeh spot #500 par hai" (indirect — ek extra trip). Kabhi kehta hai "bade ped se shuru karo (tumhari jeb mein = ek register) aur 3 kadam chalo" (displacement). Aur "PC-relative" kuch aisa hai "jahan tum khade ho, wahan se 6 kadam aage jao" — toh treasure hunt kaam karta hai chahe park game kahaan bhi set kare. Har tarah ka map sirf ek alag tarika hai yeh kehne ka ki kahan finally khodna hai.


Connections

  • Instruction Set Architecture (ISA) — addressing modes ek ISA ka ek pillar hain.
  • Instruction Format — mode bits aur address field encoding mein rehte hain.
  • Registers and Register File — base/index values ka source.
  • Memory Hierarchy — extra accesses (indirect) cache latency se interact karte hain.
  • RISC vs CISC — mainly is baat mein differ karte hain ki kitne/kitne complex modes hain.
  • Pointers and Arrays — displacement/indexed modes aise compile hote hain.
  • Stack and Subroutines — auto-increment/decrement push/pop implement karte hain.

Concept Map

mode bits select

computes

contents M of EA

no memory access

no memory access

is

is

flexibility

compactness

pointers

code compact

loops

extra memory read

Instruction bits: A, R, mode

Addressing mode rule

Effective Address EA

Operand

Immediate: operand = A

Register: operand = R contents

Direct: EA = A

Indirect: EA = M of A

Displacement: EA = A + R

PC-relative: EA = PC + A

Auto inc/dec: EA = R, adjust R