5.1.9 · D3 · HinglishInstruction Set Architecture (ISA)

Worked examplesLoad - store architecture model

5,026 words23 min read↑ Read in English

5.1.9 · D3 · Hardware › Instruction Set Architecture (ISA) › Load - store architecture model

Yeh page parent topic ki "haath gande karo" companion hai. Wahan humne argue kiya tha kyun ek CPU jo sirf load aur store ke through memory ko touch karta hai, woh jeetta hai. Yahan hum ise prove karte hain har us situation ko grind karke jo yeh model tumhare saamne rakh sakta hai: single ops, expression trees, register shortages, aur degenerate edge cases (zero memory ops, sab kuch already registers mein, har access pe cache miss).

Pehli line se pehle, teen words jinhe hum constantly use karenge, plain English mein:

Humhe do measuring sticks bhi chahiye, define karte hain pehle se use karne se pehle:

Aur teen words registers khatam hone ke baare mein, yahan define karte hain taaki spill example samajh aaye:

Ek aur word jo Example 6 se chahiye hoga — define karo abhi pehle lean karne se pehle:


Scenario matrix

Har load/store problem neeche diye gaye cells mein se ek hai (ya unka mix). Jo worked examples aate hain woh cell ke saath tagged hain, aur milke poora grid cover karte hain.

Figure — Load - store architecture model
Figure 1 — Nau scenario cells ek grid ke roop mein. Cells A–E (blue row, left) computation ki shape vary karte hain, single round-trip se lekar register spilling tak. Cells F–I (green row, right) uss par apply kiya gaya cost model vary karte hain — timing showdown, cache-miss worst case, ek word problem, aur exam trap. Poori page is grid ka walkthrough hai.

Cell Situation Kya mushkil hai Example
A Single memory→register→memory op Baseline: 1 op ko load + store chahiye Ex 1
B Expression with intermediates Results ko ops ke beech registers mein survive karna hai Ex 2
C Zero memory ops (sab registers mein) Load/store ke liye best case; minimal hai Ex 3
D Live values zyada registers se Register spilling — forced extra load/store Ex 4
E Immediate (constant) operand Literal number ke liye koi load nahi chahiye Ex 5
F Timing showdown vs register-memory Dono par compute karo, crossover nikalo Ex 6
G Degenerate: har access cache miss Limiting worst-case; jahan CPI blow up karta hai Ex 7
H Real-world word problem English → load/store plan mein translate karo Ex 8
I Exam twist: instructions AND cycles dono gino Woh trap jahan "fewer instructions" haarta hai Ex 9

Worked examples

Example 1 — Cell A: baseline round-trip

Figure — Load - store architecture model
Figure 2 — x = x + 1 ke liye baseline round-trip. Blue arrow (load) x ko left ki memory box se register R2 (counter) mein le jaata hai; ALU 1 add karta hai (yellow); red arrow (store) result ko wapas le jaata hai. Ek plus ek = do arrows wall cross karte hain = do memory accesses; beech ka add sirf registers touch karta hai.

Example 2 — Cell B: intermediates jo registers mein rehne chahiye

Figure — Load - store architecture model
Figure 3 — (a + b) - c ka expression tree. Leaves a, b, c (blue) memory se load hote hain; inner node a+b (yellow) ek intermediate hai jiske rehne ki jagah sirf register hai; root - (red) r produce karta hai. Har non-leaf node = ek value jo register mein tab tak rehni chahiye jab tak uska parent use nahi kar leta.

Example 3 — Cell C: zero memory ops (best case)

Figure — Load - store architecture model
Figure 4 — Sab operands already counter par hain. Koi arrow memory wall cross nahi karta (left par greyed out); ALU R1*R2 multiply karta hai phir R3 add karta hai, purely register-to-register. Yeh woh sabse sasta shape hai jis par ek load/store machine chal sakti hai.

Example 4 — Cell D: register pressure aur spilling

Ab ka ugly case. Socho ek toy CPU jisme sirf 3 usable registers R1,R2,R3 hain, aur humhe y = a + b + c + d compute karna hai jahan chaaon memory mein hain.

Figure — Load - store architecture model
Figure 5 — Streaming accumulation. Time left se right tak chaar steps mein chalta hai. Red bar jo poori width pe faila hua hai woh register R3 hai, running sum — yeh pehle add se store tak live rehta hai aur kabhi evict nahi hota. Chhote blue blocks transient input registers hain (R1,R2, phir R1 reused for c, phir R1 reused for d), har ek sirf tab aata hai jab zaroorat ho. Green arrow punchline hai: pressure kabhi 3 se zyada nahi hoti, isliye koi spill nahi hota.

Example 5 — Cell E: immediate operand (constants ke liye koi load nahi)

Figure — Load - store architecture model
Figure 6 — Constants kahan rehte hain. Variable a (blue) memory box se wall ke paar load hota hai. Constants 4 aur #10 (yellow) instruction word ke andar hi ride karte hain — MUL aur ADD boxes se attached small badges ke roop mein dikhaye gaye hain — isliye inhe koi memory access nahi lagti. Sirf ek arrow wall ke andar aata hai, ek bahar jaata hai.

Example 6 — Cell F: timing showdown

Yahi woh crossover hai jo parent note ne claim kiya tha. Chalo dono wall-clock times end to end compute karte hain.

Figure — Load - store architecture model
Figure 7 — Cycles as bar height (= CPI). Single red bar x86 ka ek fused instruction hai, height 10, kyunki uska hidden read-modify-write 10 cycles leta hai aur khud se overlap nahi ho sakta. Teen chhote blue bars ARM ke LDR, ADD, STR hain, har ek 4 cycles tall. Yellow arrow key reading mark karta hai: total coloured area lagbhag equal hai, aur area (bars × height ≈ total cycles) × = time, isliye dono ~4 ns mein khatam hote hain.

Task: memory[addr] = memory[addr] + R9. Numbers (illustrative, parent note se match karte hue):

  • x86 (register-memory): 1 instruction, lekin yeh read-modify-write fuse karta hai → CPI = 10, clock GHz isliye ns.
  • ARM (load/store): 3 instructions (LDR, ADD, STR), overlap ek cache miss (~10-cycle stall jo upar define kiya) hide karta hai → CPI = 4, clock GHz isliye ns.

Example 7 — Cell G: degenerate worst case (har access miss karta hai)

Figure — Load - store architecture model
Figure 8 — Cold-cache limit. Paanch mein se har memory access (red blocks) full 10-cycle miss latency pay karta hai bina kisi overlap ke — blocks end to end stack hote hain kyunki dependency chain unhe hide hone se rokti hai. Teen ALU ops (blue) sirf 1 cycle each add karte hain. Tall red total blue ko dwarf karta hai: yahan CPI blow up karta hai.

Example 8 — Cell H: real-world word problem

Figure — Load - store architecture model
Figure 9 — Sensor averaging pipeline. Do blue arrows t1 aur t2 ko unke memory addresses se R1, R2 mein load karte hain; ALU unhe add karta hai (yellow) phir ek bit right shift karta hai — right-shift binary number ko half karta hai kyunki har bit ek aisi jagah pe slide ho jaati hai jiska worth half hai. Red arrow average ko 0x28 par wapas store karta hai.

Example 9 — Cell I: exam trap (dono gino, winner chuno)

Figure — Load - store architecture model
Figure 10 — Trap visualised. Left: Machine P, sirf 2 instructions lekin har ek bahut costly hai (tall red bars, CPI 8). Right: Machine Q, 4 slim instructions (chhote blue bars, CPI 2) clock par jo do guna fast hai. Green total-time labels verdict reveal karte hain: Q ka stack real time mein 4× chota hai zyada bars hone ke bawajood.


Recall

Recall ALU op kabhi memory address kyun nahi name karta?

Kyunki load/store architecture mein sirf load/store instructions memory touch karte hain — ALU ops ko fast, fixed-latency, aur pipeline mein easy rakhte hain. ::: ALU sirf registers read/write kar sakta hai.

Recall Speed ke liye ek fair scoreboard

Execution time. ::: — kabhi sirf instruction count se nahi.

Recall Value "live" kab hoti hai, aur spill kya hai?

Live = already computed aur abhi bhi baad mein zaroorat hai; spill = ek live value ko memory mein store karna (aur reload karna) jab register pressure register count se zyada ho jaaye. ::: Spill mein ek extra store + ek extra load lagta hai.

Recall Cache hit vs cache miss latency (is page par use hoti)

Hit ≈ 1 cycle, miss ≈ 10 cycles. ::: ~10× gap hi memory timing ko variable banata hai.

Recall Example 7 se cold-cache worst-case CPI

5 misses × 10 cycles + 3 ALU × 1 cycle, 8 instructions par. ::: .

Recall Example 9 verdict

Kaun si machine jeetti hai aur kitne se? ::: Load/store machine Q, ns vs ns — 4× faster.