This page is a graded workout for the 5-stage pipeline. Every problem has a fully worked solution you can hide and re-derive. Levels climb from "can you name it?" to "can you build the reasoning yourself?". Do a level, then read its trap.
Figure s01 (below) is the mental picture behind every timing problem: rows are instructions, columns are cycles. The diagonal of coloured cells is the pipeline "filling." Count columns touched = total cycles.
IF — Instruction Fetch: read the instruction from instruction memory at the address in the PC; then PC ← PC + 4.
ID — Instruction Decode / register read: decode the opcode, read source registers from the register file, sign-extend the immediate.
EX — Execute: the ALU does arithmetic/logic, or computes a memory address, or checks a branch condition.
MEM — Memory access: loads read data memory, stores write it; everyone else idles here.
WB — Write Back: write the result into the register file.
Recall Solution L1.2
Registers are read in ID and results are written in WB. Mnemonic: Decode reads, Write writes.
Recall Solution L1.3
The four are IF/ID, ID/EX, EX/MEM, MEM/WB. Each carries data (operand values, the immediate, the ALU result, the loaded value) andcontrol signals (RegWrite, MemRead, MemWrite, …). Control decided in ID must survive all the way to WB, four cycles later — the registers ferry it there.
Step (what): apply Cycles(N)=k+(N−1). Why:k=5 cycles to fill the pipe (first result at cycle 5), then N−1 more results, one each subsequent cycle.
Cycles(8)=5+(8−1)=12.
The first instruction finishes at cycle k=5 (it must pass all five stages). Look at Figure s01: the last coloured cell of the top row sits in column 5.
Recall Solution L2.2
Step (what): take the max delay. Why: all stages share one clock; the cycle must be long enough for the slowest stage to finish, or that stage's result would not be ready to latch.
max(250,120,180,250,100)=250 ps (IF and MEM tie).Step: add the latch overhead, because every cycle also spends d writing into the pipeline register.
Tclk=250+15=265 ps.
Recall Solution L2.3
Step: cycles =k+(N−1)=5+599=604.
Step: time =604×265=160,060 ps =160.06 ns. Why multiply cycles by Tclk? Each clock cycle lasts exactly Tclk, and the cycles happen one after another; so total wall-clock time is simply "how many cycles" times "how long each cycle is."
Single-cycle time per instruction: one giant cycle must fit all combinational work plus one latch:
Tsingle=(250+120+180+250+100)+15=900+15=915 ps.Pipelined time per instruction (large N): one instruction finishes every Tclk=265 ps.
Speedup:265915≈3.45×.Why this ratio and not k+N−1Nk? Because the two machines have different cycle times here (915 vs. 265), so we compare wall-clock time per instruction directly, exactly as the intro formula box warned. Why not 5×? The stages are unbalanced: WB (100 ps) and ID (120 ps) waste much of their 265-ps slot, while IF/MEM (250 ps) set the pace. Ideal 5× requires every stage to be equal andd=0. See Clocking & Latch Overhead for why d can never be zero.
Recall Solution L3.2
lw $t0, 8($s1) : IF · ID(read s1)⋅EX(addr=s1+8) · MEM(read) · WB(write $t0). Uses all five.
sw $t5, 0($s2) : IF · ID(read s2,t5) · EX(addr = $s2+0) · MEM(write) · no WB.
Why keep idle slots? So every instruction has the identical 5-stage shape. Uniform shape ⇒ simple control ⇒ one instruction still finishes every cycle. Skipping stages would break the assembly line's steady rhythm.
Recall Solution L3.3
5-stage: Tclk=250+15=265 ps.
10-stage: Tclk=125+15=140 ps.
Step (what): form the throughput ratio 265/140≈1.89×. Why is that the throughput ratio? For a long stream, one instruction finishes every Tclk, so throughput = 1 / Tclk (instructions per second). Comparing two throughputs is therefore 1/Tclknew1/Tclkold=TclknewTclkold=140265 — throughput scales as the inverse of the cycle time, so a smaller Tclk is proportionally faster.
The result 1.89× is less than the naive 2× you'd hope for by doubling stages. Why? The latch overhead d did not shrink; it is now 15/140≈10.7% of the cycle instead of 15/265≈5.7%. As stages get thinner, d eats a bigger fraction. Push far enough and speedup saturates or reverses.
Both IF and MEM are 250 ps. Splitting either drops its halves to 125 ps, but the other 250-ps stage still remains and re-sets the max. So one split alone does not lower maxti below 250 — the new bottleneck is still the un-split 250-ps stage.
maxti=250 ps still⇒Tclk=250+15=265 ps (unchanged!).Insight: you must split both 250-ps stages to see any gain. Splitting only one wastes an extra latch for nothing. This is the core lesson: the second-slowest stage caps how much helping the slowest can achieve. Balance is global, not local.
Recall Solution L4.2
Set pipelined time < single-cycle time:
(k+N−1)Tclk<N⋅Tsingle(5+N−1)(265)<N(915)(N+4)(265)<915N265N+1060<915N1060<650N⇒N>1.63.
So from N=2 onward the pipeline already wins. Why so early? The single-cycle machine's per-instruction cost (915) is enormous next to 265; the fill penalty of only 4 extra cycles is paid off almost immediately.
(a)max(300,200,350,300,150)=350; Tclk=350+25=375 ps.
(b) Cycles =k+(N−1)=5+999=1004.
(c) Time =1004×375=376,500 ps =376.5 ns.
(d) Total work =300+200+350+300+150=1300 ps; single-cycle =1300+25=1325 ps/instr. Large-N pipelined ≈375 ps/instr. Speedup =1325/375≈3.53×.
(e) Balanced ideal: each stage =1300/5=260 ps, so Tclk=260+25=285 ps, giving 1325/285≈4.65× — still not 5×. The theoretical 5× needs d=0 too, but latch overhead can never be zero (real flip-flops have setup + propagation time — see Clocking & Latch Overhead). Hazards would erode it further.
Recall Solution L5.2
Recall a stall cycle = an inserted empty cycle that delays an instruction until its needed value is reachable. Lay both instructions on a timeline; rows are instructions, columns are clock cycles (c1…c7), each cell is the stage that instruction occupies that cycle.
**Step 1 — find when t0isproduced(reachable).∗∗‘add‘writest0 in its WB, which is cycle 5:
instruction
c1
c2
c3
c4
c5
add
IF
ID
EX
MEM
WB
**Step 2 — find when sub needs t0.∗∗‘sub‘readsitssourcesin∗∗ID∗∗.Back−to−back,‘sub‘′sIFisc2,soits∗natural∗IDisc3.∗∗Step3—applythehardwarerule.∗∗Nosame−cyclewrite−then−readmeans‘sub‘′sIDcanonlyruninthecycle∗∗after∗∗‘add‘′sWB—i.e.‘sub‘′sIDmustmovefromc3to∗∗c6∗∗.∗∗Step4—countthestalls.∗∗NaturalID=c3,requiredID=c6,so‘sub‘isdelayedby6 - 3 = 3$ cycles → 3 stall cycles. The corrected timeline:
instruction
c1
c2
c3
c4
c5
c6
c7
c8
c9
add
IF
ID
EX
MEM
WB
sub
IF
–
–
–
ID
EX
MEM
WB
(the three "–" cells are the inserted bubbles).
Step 5 — total cycles. Without stalls two instructions would take k+(N−1)=5+1=6 cycles; the 3 bubbles push sub back by 3, giving 6+3=9 cycles total (last cell WB in c9). Why forwarding fixes it: the ALU result exists right after add's EX (c3) — feed it straight into sub's EX and all 3 stalls vanish, back to 6 cycles. This is the entire motivation for Data Forwarding / Bypassing.
Recall Solution L5.3
Goal: show k+N−1Nk<k. Step 1 — clear the fraction. Since k+N−1>0, multiply both sides by it without flipping the inequality:
k+N−1Nk<k⟺Nk<k(k+N−1).Step 2 — expand the right side. Distribute k:
k(k+N−1)=k2+kN−k.Step 3 — cancel the common kN term. Both sides carry kN (left is Nk), so subtract it:
Nk<k2+kN−k⟺0<k2−k.Step 4 — factor and interpret.k2−k=k(k−1). For any real pipeline k≥2, both k and k−1 are positive, so k(k−1)>0 is always true — but notice this step used onlyk≥2, independent of N. Wait: we cancelled kN assuming the strict form; the strictness in fact requires N≥2 so that the pipeline is genuinely overlapping (at N=1 both sides equal k). Hence for every finite N≥2 the strict inequality holds.
Step 5 — the limit. Equality would need k(k−1)=0, impossible for k≥2; but as N→∞ the "−1" in k+N−1 becomes negligible and the ratio approachesk. Meaning: the fill/drain overhead of (k−1) cycles can be amortized toward nothing but never actually removed for a finite stream.
What is Tclk in terms of stage delays and latch overhead?
Tclk=maxi(ti)+d — the slowest stage plus the latch cost every cycle pays.
Cycles to run N instructions through a k-stage pipeline, no stalls?
k+(N−1) — fill with k, then one result per cycle.
Why does splitting only the single slowest stage often not help?
The second-slowest stage becomes the new bottleneck; maxti may not drop, so Tclk is unchanged.
Why can real speedup never reach exactly k×?
Latch overhead d>0, unbalanced stages waste slots, and hazards add stalls; k+N−1Nk<k for all finite N.
What assumption lets us write speedup as k+N−1Nk?
Both machines share the same Tclk; when cycle times differ (single-cycle vs. pipelined), compare wall-clock times directly instead.
What is a stall cycle?
An inserted empty (bubble) cycle where a stage does no useful work because it is waiting for a not-yet-reachable value or resource; it adds one to the cycle count.