5.1.3 · D5 · HinglishInstruction Set Architecture (ISA)

Question bankAddressing modes

1,416 words6 min read↑ Read in English

5.1.3 · D5 · Hardware › Instruction Set Architecture (ISA) › Addressing modes

Neeche use kiye gaye reminders, sab parent note mein banaye gaye hain: = instruction word ke andar carry kiya gaya address/displacement field; = register ka contents; = address par memory ka contents; = effective address, mode ka rule apply hone ke baad operand ki final location.


Sach ya jhooth — justify karo

Sach ya jhooth: immediate mode apna operand fetch karne ke liye ek memory access karta hai.
Jhooth. Operand instruction word ke andar field hi hai, to wo instruction fetch ke dauran opcode ke saath aa jaata hai — operand ke liye zero extra memory accesses.
Sach ya jhooth: direct (absolute) mode mein operand value ke barabar hota hai.
Jhooth. Direct mode mein address hai; operand hai, us address par jo contents hain. ek location hai, value nahi.
Sach ya jhooth: register mode aur register-indirect mode dono zero memory accesses lete hain.
Jhooth. Register mode operand seedha register se padhta hai (0 accesses), lekin register-indirect ko ek address ki tarah use karta hai, to memory ek baar padhta hai: , operand .
Sach ya jhooth: indirect mode ko operand get karne ke liye hamesha exactly do memory accesses chahiye hote hain.
Memory-indirect ke liye Sach: pointer fetch karne ke liye ek read, operand fetch karne ke liye doosra. Wo extra read indirection ki kimat hai.
Sach ya jhooth: PC-relative branches apne target ka absolute address store karte hain.
Jhooth. Wo ek offset store karte hain; CPU compute karta hai. Distance store karna fixed address ki jagah exactly wahi hai jo code ko relocatable banata hai.
Sach ya jhooth: displacement mode aur indexed mode alag arithmetic use karte hain.
Jhooth. Arithmetic identical hai (constant plus register). Sirf roles alag hain: displacement ko fixed base treat karta hai aur ko compile-time-varying offset; indexed ko base treat karta hai aur ko loop-varying index.
Sach ya jhooth: zyada addressing modes add karne se programs hamesha tez chalte hain.
Jhooth. Fancy modes instruction count ghataate hain lekin decode logic aur pipeline critical path lambi kar sakte hain — ek classic RISC vs CISC trade-off hai, koi free win nahi.
Sach ya jhooth: immediate mode arbitrarily bada constant hold kar sakta hai.
Jhooth. Constant instruction ke field mein rehta hai, to uski range us field ki bit width se capped hoti hai. Bade constants ke liye extra instructions ya ek memory load chahiye.

Error dhundho

LOAD (100) indirect hai, to operand hai. Error kahan hai?
Parentheses ka matlab indirect hai: pehle (pointer), phir operand . Sirf padhna direct wala answer hai.
"Register-indirect register padhta hai, ek value milti hai, aur wo value operand hai." Error?
Register ke contents address ki tarah use hote hain, operand ki tarah nahi. , phir operand hai — ek memory read phir bhi hoti hai.
"PC-relative branch: maine program 1000 bytes upar load kiya, to mujhe har branch ka stored number patch karna hoga." Error?
Tum kuch bhi patch nahi karte. Branches relative offsets store karte hain, to code ke saath saath shift hota hai; yahi position independence ka poora point hai.
"Auto-increment (R1)+ pehle R1 increment karta hai, phir memory read karta hai." Error?
Auto-increment ke liye read pehle current value par hoti hai (), phir step up karta hai. Auto-decrement wala hai jo access se pehle register adjust karta hai.
"Direct mode bade arrays ke liye best hai kyunki tum bas har element ka address naam se bulate ho." Error?
Direct ko har access ke liye ek full-width address baked in chahiye aur wo ek register vary karke loop nahi kar sakta. Arrays displacement/indexed mode use karte hain taaki ek base register plus ek changing offset saare elements ko cheaply walk kare.
"Displacement mode do memory accesses leta hai: ek A+(R) ke liye aur ek operand ke liye." Error?
compute karna CPU ke andar arithmetic hai (ALU), memory access nahi. Sirf operand fetch memory touch karta hai — total ek access.

Why questions

Indirect mode kyun exist karta hai jab extra memory access ki kimat chukani padti hai?
Kyunki target address run time par decide kiya ja sakta hai — pointers, linked lists, aur dispatch tables (Pointers and Arrays) follow karne ke liye ek address data mein stored chahiye, jo sirf memory read supply kar sakti hai.
Displacement mode ko "workhorse" kyun kehte hain?
Ye seedha real code par map hota hai: ek base hold karta hai (array start, struct address, ya stack-frame pointer) aur ek small compile-time offset hai, to array[i], struct.field, aur local variables sab ek cheap instruction ban jaate hain.
Stacks auto-increment / auto-decrement kyun prefer karte hain?
Push aur pop ko har baar stack pointer move karna hota hai. Access mein step bake karne ka matlab hai ki push/pop ko koi alag add/subtract instruction nahi chahiye.
PC-relative addressing shared/relocatable code ke liye essential kyun hai?
Kyunki operating system program ko kisi bhi base address par load kar sakta hai; se offsets valid rehte hain chahe code kahin bhi land ho, jabki absolute targets break ho jaate.
Immediate mode sabse fast operand access kyun deta hai?
Value already fetched instruction ke andar travel karti hai, to koi alag address compute nahi karna aur koi memory hierarchy round-trip nahi — zero extra accesses.
Ek RISC design deliberately sirf kuch addressing modes kyun support karta hai?
Kam modes ka matlab simpler, zyada uniform decoding aur ek shorter, zyada pipelineable critical path hota hai — per-instruction cleverness ko higher clock speed aur throughput ke liye trade karna.

Edge cases

Immediate mode mein hone par operand kya hota hai?
Operand simply constant hota hai; koi memory touch nahi hoti. Direct mode se compare karo jahan ka matlab "read " hoga, ek actual location.
Indirect mode mein, agar pointer cell mein khud hi stored ho (self-pointer) to kya hoga?
, to operand phir — indirection ka ek level theek resolve hota hai; CPU pointer ko fixed number of times hi follow karta hai, endlessly loop nahi karta.
Auto-increment ke liye word size (hamesha 1 nahi) kyun matter karta hai?
Register ko ek element ke size se step karna chahiye, to byte data use karta hai lekin ek 4-byte word use karta hai; galat use karne se elements skip ya overlap ho jaate.
Auto-decrement mein, agar valid range se neeche decrement ho jaaye to kya danger hai?
allocated region se past underflow ho sakta hai (jaise stack overflow into other data), kyunki mode read se pehle blindly karta hai — bounds programmer ki responsibility hai, mode ki nahi.
PC-relative mode ke liye, offset kya compute karta hai?
, yaani current instruction ka reference point khud — effectively ek branch-to-self ya ek no-displacement reference, legal lekin usually degenerate case.
Agar register-indirect ek aisa register use kare jisme ek address stored ho jo kisi doosre register ke contents ke barabar ho, to kya dono modes phir bhi alag hain?
Arithmetic result coincide kar sakta hai, lekin modes rule se define hote hain, runtime value se nahi; register-indirect () aur base+index () ka distinction tab bhi bana rehta hai jab numbers happen to match karein.

Recall Ek-sentence survival rule

Har mode ke liye ek formula hai plus memory accesses ka count — wo do facts per mode commit karo aur is page ka koi bhi trap tumhe pakad nahi sakta.