Exercises — Load - store architecture model
5.1.9 · D4· Hardware › Instruction Set Architecture (ISA) › Load - store architecture model
Yahan sab kuch parent note par build karta hai. Agar koi symbol unfamiliar lage, to yeh poori glossary hai jo hum puri page reuse karenge — ek baar zaroor padho:
Level 1 — Recognition
L1.1 — Illegal instruction dhundo
Neeche ek load/store machine ke liye chaar candidate instructions hain. Exactly ek nahi ho sakta ek pure load/store ISA mein. Kaun sa, aur kyun?
(a) LDR R1, [R2] (b) ADD R1, R2, R3
(c) ADD R1, [R2], R3 (d) STR R1, [R2]
Recall Solution
Answer: (c).
Ek load/store architecture ka ek hi defining rule hai: sirf load aur store memory ko touch karte hain; ALU sirf registers dekhta hai. Instruction (c) ADD (ek ALU op) se seedha memory [R2] padhne ko keh raha hai — yeh forbidden hai.
- (a) ek load hai — memory touch karna allowed. ✓
- (b) ek ALU op hai teen registers par, koi memory nahi. ✓
- (d) ek store hai — memory touch karna allowed. ✓
- (c) ek ALU op hai memory operand ke saath → yahan illegal (yeh x86 jaise register-memory machine par legal hai, jo exactly woh contrast hai jo parent note draw karta hai).
L1.2 — Family ka naam batao
Har blank fill karo.
x86 jo ADD [addr], EAX allow karta hai woh ek register-memory architecture hai.
MIPS/ARM/RISC-V jo load-then-compute-then-store force karta hai woh ek load/store (register-register) architecture hai.
Recall Solution
ADD [addr], EAXek memory read + arithmetic + memory write ko ek instruction mein fold karta hai → register-memory (ise "CISC-style memory model" bhi kehte hain).- Strict load → compute → store separation load/store model hai, jise register-register bhi kehte hain. Wider debate ke liye RISC vs CISC philosophy dekho.
Level 2 — Application
L2.1 — Load/store mein translate karo
Is register-memory line ko legal load/store instructions mein convert karo. Maan lo R10 mein already x ka address hai, aur tum scratch registers R1, R2 use kar sakte ho.
ADD [x], R5 ; matlab: memory[x] = memory[x] + R5
Recall Solution
Yeh fused instruction teen hidden cheezein karti hai: x padho, R5 add karo, x wapas likho. Inhe alag karo:
LDR R1, [R10] ; R1 = memory[x] (load)
ADD R1, R1, R5 ; R1 = R1 + R5 (ALU, sirf registers)
STR R1, [R10] ; memory[x] = R1 (store)
Ek register-memory instruction teen load/store instructions ban gayi — parent ke formula se match karta hai .
L2.2 — Formula se instructions count karo
Ek computation ko arithmetic operations chahiye, loads aur stores chahiye. Register-memory machine par, 5 ops mein se 3 har ek mein ek memory operand absorb kar sakte hain (to 3 memory accesses ALU ops mein ghus jaati hain).
(a) Load/store par instruction count, ? (b) Register-memory par instruction count, ? (Har fused op exactly ek alag memory instruction hatata hai.)
Recall Solution
(a) Load/store sab kuch alag rakhta hai: (b) Register-memory: 3 fused ops mein se har ek ek memory access nigal leta hai, 3 alag load/store instructions hata ke: To register-memory version kam instructions run karta hai (8 < 11) — lekin agle mistake box padho khush hone se pehle.
L2.3 — Frequency se clock period nikalo
Ek ARM core par run karta hai. Uska clock period nanoseconds mein kya hoga?
Recall Solution
(Ek tick ek nanosecond ka teesra hissa rehta hai. Yeh hamare master equation mein "seconds per step" hai.)
Level 3 — Analysis
L3.1 — Full time comparison
Dono machines ke liye usi task par total execution time compute karo, parent note ke numbers use karke.
- x86 (register-memory): , , (to ).
- ARM (load/store): , , (to ).
Yeh figure dono timelines ko side by side dikhata hai.

Recall Solution
mein plug karo: Dono tie karte hain ≈4.0 ns par. Extra ARM instructions () exactly cancel ho jaati hain uske lower CPI () aur higher clock () se. Yahi parent note ka poora point hai: load/store trade karta hai zyaada instructions ko lower CPI aur higher clock ke liye. Real silicon mein yeh tie usually ARM ki taraf tip karta hai jab Instruction pipelining load latency hide kar leta hai.
L3.2 — CPI = 4 kahan se aata hai?
ARM sequence teen instructions ka hai aur steady state mein 12 pipeline cycles leta hai (ek memory miss doosre kaam ke peeche chhupi, plus pipeline fill). Dikhao ki , aur alag se dikhao ki x86 ka fused instruction par kyun rehta hai.
Recall Solution
CPI total cycles ko instruction count se divide karna hai:
x86 ka fused ADD [addr], EAX apna internal read → modify → write overlap nahi kar sakta; poori ~10-cycle memory latency ek indivisible instruction ke roop mein expose hoti hai:
Key insight: ARM ki jeet yeh nahi hai ki har memory access ke fewer cycles hain — yeh hai ki pipelining doosre instructions ko miss ke dauran run karne deta hai, to average per-instruction cost gir jaati hai.
L3.3 — Tie todo
Maan lo engineers ARM ki pipeline improve karte hain to 3-instruction sequence ab 9 cycles mein khatam ho jaati hai 12 ki jagah (better latency hiding). rakho. Naya ? Ab kaun jeetta hai?
Recall Solution
Naya CPI: Naya time: Ab : ARM jeetta hai. Better latency hiding (deeper/smarter pipelining, out-of-order issue) directly CPI aur isliye total time kam karta hai, even though instruction count kabhi nahi badla.
Level 4 — Synthesis
L4.1 — Ek poora expression hand-schedule karo
Is expression ke liye legal load/store assembly likho:
Maan lo R10, R11, R12 mein a, b, c ke addresses hain, aur R13 mein d ka address. Immediate #3 use karo. Phir batao ki sabse busy moment par kitne registers mein live intermediate values ek saath hain.
Recall Solution
LDR R1, [R10] ; R1 = a
LDR R2, [R11] ; R2 = b
ADD R3, R1, R2 ; R3 = a + b (intermediate 1)
LDR R4, [R12] ; R4 = c
ADD R5, R4, #3 ; R5 = c + 3 (intermediate 2)
MUL R6, R3, R5 ; R6 = (a+b)(c+3)
STR R6, [R13] ; d = R6
Sabse busy moment: MUL se thoda pehle, dono partial results ek saath alive hone chahiye — R3 = a+b aur R5 = c+3. Yeh 2 live intermediates hain. Isi liye load/store ISAs mein bahut saare registers hote hain (RISC-V/MIPS mein 32): intermediates memory mein spill karne ki jagah registers mein rahte hain. Register allocation dekho.
L4.2 — Sab kuch count karo
L4.1 program ke liye , , (ALU ops), aur total batao. Verify karo .
Recall Solution
- Loads:
LDR R1, LDR R2, LDR R4→ . - Stores:
STR R6→ . - ALU ops:
ADD, ADD, MUL→ . - Total lines: . Check: ✓
L4.3 — Register spill
Ab maan lo ek tiny machine hai jisme sirf registers R1, R2 data ke liye usable hain (ek stress test). Phir bhi tumhe compute karna hai. Kyunki tum dono intermediates ek saath hold nahi kar sakte, tumhe ek ko memory mein spill karna hoga (ek scratch slot [SP]). L4.1 plan ke comparison mein spilling kitne extra load/store instructions add karti hai?
Recall Solution
2 registers ke saath tum pehle a+b compute karte ho, lekin jab c+3 compute karo tab usse rakhne ki jagah nahi hai, to tum usse [SP] par store karte ho, doosra sum karte ho, phir multiply ke liye usse wapas load karte ho:
LDR R1, [R10] ; a
LDR R2, [R11] ; b
ADD R1, R1, R2 ; R1 = a+b
STR R1, [SP] ; a+b ko memory mein SPILL karo <-- extra store
LDR R1, [R12] ; c
ADD R1, R1, #3 ; R1 = c+3
LDR R2, [SP] ; a+b RELOAD karo <-- extra load
MUL R1, R2, R1 ; product
STR R1, [R13] ; d
L4.1 ke comparison mein extra instructions: ek store + ek load = 2 extra. Yeh hai concrete cost bahut kam registers ki, aur precisely isi liye load/store designs large register files prefer karte hain. Register allocation aur Memory hierarchy dekho.
Level 5 — Mastery
L5.1 — Real-time deadline ke under design decision
Tum ek anti-lock braking controller ke liye CPU design kar rahe ho. Hard requirement yeh hai: har instruction ka worst-case time jaana aur bounded hona chahiye taaki tum prove kar sako ki ek control loop hamesha deadline ke andar khatam ho. Tum register-memory ya load/store choose kar sakte ho. Kaun sa choose karoge, aur ek-sentence engineering reason do jo mein grounded ho.
Recall Solution
Load/store choose karo. Iske arithmetic instructions ka fixed, low CPI hota hai (woh kabhi memory touch nahi karte), aur memory latency explicit loads/stores mein isolate hoti hai jise tum alag se bound kar sakte ho — isliye har instruction ka worst-case cycle cost predictable hota hai, jo exactly woh cheez hai jo ek provable real-time deadline ko chahiye. Ek register-memory ADD [addr] variable cache latency ko ek arithmetic instruction ke andar chhupaata hai, jisse uska CPI (aur isliye ka uska hissa) unpredictable ho jaata hai.
L5.2 — Register-memory kab accept karoge?
Ek concrete situation do jahan register-memory model ka fewer instructions genuinely help karta hai, upar sab kuch ke bawajood.
Recall Solution
Jab instruction-fetch bandwidth ya code size bottleneck ho — jaise ek memory-constrained embedded device, ya aisa workload jahan instruction cache thrash kare. Kam, denser instructions () matlab fetch aur store karne ke liye fewer bytes, Memory hierarchy aur Instruction encoding par pressure kam. Yeh ek bada part hai kyun x86 ki dense CISC encoding survive ki: legacy code density aur I-cache footprint. Yeh trade-off usi equation mein rehta hai — tum higher CPI accept karte ho aur fetch traffic shrink karne ke liye.
L5.3 — Crossover prove karo
use karke, ARM steady-state cycle count (3-instruction sequence ke liye) dhundo jis par ARM exactly x86 se tie kare. x86 ko par rakho aur ARM ko () par. Yaad karo , to ARM ka time hai.
Recall Solution
Note karo ki — total cycle count hi woh product hai. To: x86 ke barabar set karo: To 12 cycles exactly tie point hai — L3.2 se match karta hai. Koi bhi pipeline improvement jo ARM ko 12 total cycles se neeche laaye (jaise L3.3 ke 9 cycles) load/store ko winner banata hai; 12 se upar kuch bhi lose karta hai.
Recall Quick self-check (sab try karne ke baad reveal karo)
Load/store ISA mein sirf load aur store memory touch karte hain ::: True — defining rule. Load/store instruction count ka formula ::: . Master timing equation ::: . 3 GHz par ::: . Load/store zyaada instructions ke bawajood x86 se tie kyun kar sakta hai ::: lower CPI aur higher clock bade ko cancel kar dete hain. Bahut kam registers ki cost ::: register spilling extra store+load instructions add karta hai.
Related: RISC vs CISC philosophy · Instruction pipelining · Register allocation · Addressing modes · Instruction encoding · Memory hierarchy