5.1.3 · Hardware › Instruction Set Architecture (ISA)
Ek addressing mode woh rule hai jo CPU use karta hai yeh figure out karne ke liye ki operand actually kahan hai — instruction ke andar ke bits se. Instruction chhota hota hai; memory bahut badi hoti hai. Addressing modes alag-alag "recipes" hain jo kuch bits ko ek real operand mein convert karti hain — ek number, ek register, ya ek memory address.
Ek instruction word sirf, maan lo, 32 bits ka hota hai. Lekin humein 2 32 memory locations mein se kisi bhi ek ko point karna pad sakta hai, loops use karne padte hain, arrays mein index karna padta hai, pointers follow karne padte hain, aur code compact rakhna padta hai. Ek fixed rule yeh sab nahi kar sakta. Isliye ISA kai rules offer karta hai aur instruction mein kuch mode bits ko allow karta hai jo select karein ki kaunsi recipe apply hogi.
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.
Definition Effective Address (EA)
Effective address woh final memory address hota hai operand ka, jo addressing-mode rule apply hone ke baad milta hai. Formally, har mode ke liye hum ek function define karte hain:
E A = f ( bits in instruction , register contents , PC )
Operand phir ya toh us address ka content M [ E A ] hota hai, ya (register/immediate modes ke liye) bina kisi memory access ke milta hai.
Maan lo instruction mein ek field A hai (ek address ya displacement) aur possibly ek register name R . M [ x ] ka matlab hai "memory ka content x par" aur ( R ) ka matlab hai "register R 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 A itna wide hona chahiye ki kisi bhi location ko naam de sake.
Indirect — A 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 (A + ( R ) ) — yeh workhorse mode hai. R ek base hold karta hai (array/struct/stack frame ka start), A 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.
Maan lo memory aur registers:
Address
Contents
Register
Contents
100
500
R1
400
400
700
R2
3
500
800
PC
200
403
900
Worked example Example 1 — Direct vs Indirect same
A = 100 par
Direct: LOAD 100 → E A = 100 , operand = M [ 100 ] = 500 .
Yeh step kyun? Direct ka matlab hai address field hi EA hai, toh hum location 100 ko ek baar read karte hain.
Indirect: LOAD (100) → E A = M [ 100 ] = 500 , operand = M [ 500 ] = 800 .
Yeh step kyun? Pehla read pointer (500) laata hai; us pointer par doosra read actual data (800) laata hai. Yeh woh extra memory access hai jo indirect hamesha pay karta hai.
Worked example Example 2 — Displacement / based mode
LOAD 3(R1) jahan A = 3 , ( R 1 ) = 400 .
Step 1: E A = A + ( R 1 ) = 3 + 400 = 403 . Kyun? Base register R1 array ke start par point karta hai; 3 element offset hai.
Step 2: operand = M [ 403 ] = 900 .
Yeh exactly waise hai jaise array[3] compile hota hai jab R1 = array ka base ho.
Worked example Example 3 — Indexed with a scale in spirit
LOAD 100(R2) jahan R2 index ki tarah use ho raha hai, ( R 2 ) = 3 .
E A = 100 + 3 = 103 ; operand = M [ 103 ] .
Yeh step kyun? Same arithmetic jaise displacement, lekin role alag hai: yahan constant base hai aur register varying index hai — loops ke liye great jo R2 increment karte hain.
Worked example Example 4 — PC-relative branch
BRANCH +6 jab P C = 200 .
E A = P C + A = 200 + 6 = 206 . Kyun? Target ek distance ke roop mein store hota hai, toh same code tab bhi sahi kaam karta hai jab OS program ko kisi alag base address par load kare — position independence.
Worked example Example 5 — Auto-increment (streaming)
LOAD (R1)+ jab ( R 1 ) = 400 , word size d = 1 .
Step 1: E A = ( R 1 ) = 400 ; operand = M [ 400 ] = 700 .
Step 2: R 1 ← 400 + 1 = 401 automatically.
Kyun? Agla iteration next element ko zero extra instructions mein read karta hai — while(*p++) ke liye ideal.
Common mistake "Immediate mode memory se read karta hai."
Kyun sahi lagta hai: har doosra mode ek memory read ke saath khatam hota hai, toh assume karte hain yeh bhi karta hoga.
Fix: immediate operand instruction word ke andar hi hota hai — 0 memory accesses. Value opcode ke saath travel karti hai.
Common mistake "Indirect aur register-indirect same hain."
Kyun sahi lagta hai: dono ke naam mein "indirect" hai aur dono pointer fetch karte hain.
Fix: Register indirect mein pointer already ek register mein hota hai (E A = ( R ) , ek memory access). Memory indirect mein pointer memory mein hota hai, toh pointer paane ke liye memory read karo phir wahan bhi read karo (E A = M [ A ] , do accesses).
Common mistake "PC-relative ek absolute target address use karta hai."
Kyun sahi lagta hai: hum jumps ko "go to line 206" ki tarah sochte hain.
Fix: instruction current PC se ek offset store karta hai. CPU P C + A compute karta hai. Offsets store karna hi code ko relocatable banata hai.
Common mistake "Zyada addressing modes hamesha faster programs banate hain."
Kyun sahi lagta hai: fancy modes instruction count reduce karte hain.
Fix: complex modes decoding aur critical path ko lambi kar sakte hain (ek CISC concern). RISC often kam modes rakhta hai simpler, faster pipeline ke liye. Yeh ek trade-off hai, free win nahi.
Intuition Agar sirf ek cheez yaad rakho
Har mode sirf E A ke liye ek formula hai. Woh formula likhna seekho aur memory accesses count karo — baaki sab khud se aata hai. Do modes jo har jagah milte hain woh hain register (fastest) aur displacement E A = A + ( R ) (arrays, structs, stacks). Sirf yeh do master karo aur tumne ~80% real instructions cover kar li hain.
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 .
Mnemonic Family yaad karo
"I Really Dig Into Data Instantly, Precisely, Automatically" →
I mmediate, R egister, D irect, I ndirect, D isplacement, I ndexed, P C-relative, A uto-increment/decrement.
Aur golden rule: arrows count karo — har "look it up" (M [ ⋅ ] ) ek memory access hai.
Instruction bits: A, R, mode
Register: operand = R contents
Auto inc/dec: EA = R, adjust R