The assembly line in silicon

After this lesson you will push five instructions through the five stages of the RISC-V pipeline cycle by cycle, say what each pipeline register carries, and compute how long any program takes on an ideal pipeline — and why it is never the 5× the notes promise.

Take five instructions and a processor whose five stages take 2 ns each. One instruction after another: 5 × 10 ns = 50 ns. Overlapped on the pipeline: 18 ns. Next to that 18 ns the notes print "a speedup of 5×". Divide 50 by 18 and you get 2.78.

Where did the other half of the promised speedup go, and when, if ever, do you get it back? The answer is one subtraction — and it is the same subtraction that puts the "+4" into the cycle-count formula on the A4 sheet you are allowed to bring to the exam.

One more number before you start. In March 2026 the first self-assessment test of this course — on the basics of pipelining, hazards and caches — was taken by 124 students; the average score was 5.3 out of 10 (WeBeep, week 2). The basics are examined, and they are missed.

Five stops for every instruction

Here is the loop this whole lesson runs on. It is written the way the exam papers write assembly: capital mnemonics, F registers for floating-point values, R registers for integers, and the memory address as an offset in front of a base register in brackets. The papers of 2024 and 2025 wrote the registers as $F2 and $R1; the 2026 paper dropped the dollar sign, and so does this notebook.

LOOP:  LD    F2, 0(R1)
       FADD  F4, F2, F0
       SD    F4, 0(R1)
       ADDUI R1, R1, 8
       BNE   R1, R2, LOOP

Read it once in words: load the number at address R1 into F2; add F0 to it and put the sum in F4; store F4 back to the same address; move the pointer R1 on by 8 bytes; go back to LOOP unless R1 has reached R2. The instructions are numbered I0 to I4 as the papers number them. The machine of this lesson is the one of the notes: five stages, one clock cycle each, and every instruction — the FADD included — spends exactly one cycle in the execute stage. Real floating-point adders take several cycles; that pipeline arrives in lesson 7.

The RISC-V subset of the notes, in three spellings

The notes (pp. 8–9) introduce the instruction set in three families, with the effect of each instruction written as a register transfer: ALU instructions (add rd, rs1, rs2 does rd ← rs1 + rs2; addi adds a constant), load and store instructions (ld rd, offset(rs1) does rd ← M[rs1 + offset]; sd rs2, offset(rs1) does the reverse) and branches and jumps (beq, bne, j, jr). These are the only kinds of instruction the pipeline ever sees. The same instructions appear in three spellings during the course, and you must read all three fluently, because the exam is written in the third.

Same instruction, three spellings. The notes switch between the first two; the exam papers use the third.
What it doesRISC-V, notes pp. 8–12MIPS style, notes pp. 16–17Exam papers
load from memory into a registerld x10, 40(x1)lw $x, offset($y)LD F2, 0(R1)
store a register to memorysd x5, 8(x1)sw $x, offset($y)SD F4, 0(R1)
register + registeradd x3, x1, x2op $x, $y, $zFADD F4, F2, F0
register + constantaddi x1, x1, 8—ADDUI R1, R1, 8
conditional branch (not equal / equal)bne x1, x2, L1, beq x1, x2, L1beq $x, $y, offset (the notes' only MIPS-style example)BNE R1, R2, LOOP
register namesx0 … x31$x, $y, $zR1, R2 … and F0, F2 … (2024–25: $R1, $F2)

Two small things to know about the first spelling. The notes use ld and sd, the 64-bit load and store of RV64, and on p. 10 call the registers 32-bit wide; in RV64 they are 64 bits (the width is called XLEN). And the notes' j and jr are pseudo-instructions. None of this matters for the exam; the mnemonics of the papers do.

What happens at each stop

Every instruction visits the same five stages in the same order. Walk LD F2, 0(R1) through them — it is the notes' Example 1 (p. 12), ld x10, 40(x1), in the papers' spelling:

  1. IF, instruction fetch. The program counter (PC) addresses the instruction memory; the instruction word comes out, and a separate adder computes PC + 4, the address of the next instruction. (Separate, so that IF never needs the ALU while EX is using it for another instruction.)
  2. ID, instruction decode. The opcode is decoded, the register file is read — here R1 — and the immediate 0 is extracted and sign-extended.
  3. EX, execute. The ALU adds R1 + 0: the memory address.
  4. MEM, memory access. The data memory is read at that address.
  5. WB, write-back. The word that came out of memory is written into F2.

Now look at the hardware those five steps use, and you will see why there are exactly five of them and not four or six. Each step uses a different resource, and uses it once: the instruction memory, the two read ports of the register file, the ALU, the data memory, the one write port of the register file. The notes list these components on pp. 10–11; the register file has two read ports and one write port because every RISC-V instruction reads at most two registers and writes at most one. That one-resource-per-stop property is the precondition for everything that follows: five instructions can occupy the five stops at the same time without fighting over hardware.

five resources, each used once IF ID EX MEM WB PC Instr. memory Reg. file read ×2 ALU Data memory Reg. file write ×1 the result returns to the registers
Fig. 1. The datapath of the notes' Fig. 1 (p. 10) redrawn as five stops. The blue path is the one loop in the flow of data: a result written into the register file in WB, where a later instruction reads it in ID. (The other backward path, a branch target into the PC, is the subject of lesson 4.)

"RISC-V adopts a Harvard architecture, so there are no structural hazards." The notes come close to this on p. 10 ("RISC-V adopts a Harvard Architecture style … This prevents structural hazards"). Separate instruction and data memories are a choice of the implementation — in a real chip two level-1 caches in front of one memory — made so that the fetch of one instruction and the memory access of another never compete. It is not a property of the RISC-V instruction set, and a RISC-V processor with a single memory port, or with a multi-cycle divider, has structural hazards all the same. Keep the reasoning, drop the "RISC-V adopts".

Five stages because five resources: instruction memory, register read ports, ALU, data memory, register write port — each used once per instruction.

Overlap, not speed: the assembly line

In a car factory nobody waits for one car to be finished before the next body enters the line. Each station does its one job and passes the car on; a new car rolls off the end at the pace of the slowest station, not at the pace of a whole car. The notes (p. 13) use the same picture, and it is exact: the five stops of Fig. 1 are the five stations, and the instructions are the cars.

Pipelining was born as a disappointment. IBM's 7030 "Stretch" was promised to be 100 times faster than the IBM 704; it came out about 30 times faster, IBM cut its price from 13.5 to 7.78 million dollars and sold nine. But its "lookahead" unit, which overlapped the fetching and decoding of instructions with the execution of earlier ones, is the ancestor of every pipeline in this course.

Take the notes' numbers: 2 ns per stage, so 10 ns per instruction. Without overlap, five instructions take 50 ns — each one must leave the last stop before the next enters the first. With overlap, the second instruction enters IF while the first moves to ID, and so on. The first instruction still needs the full 10 ns; after that one instruction completes every 2 ns.

I0 IF ID EX ME WB I1 IF ID EX ME WB I2 0 10 ns 20 ns 10 ns each, 50 ns for five

Before: one instruction after another

I0 IF ID EX ME WB I1 IF ID EX ME WB I2 IF ID EX ME WB I3 IF ID EX ME WB I4 IF ID EX ME WB 0 8 ns 18 ns all five stops busy

After: overlapped on the pipeline

Fig. 2. The notes' Fig. 3 (p. 13) as a before/after pair, 2 ns per stage. Left: 50 ns for five instructions. Right: 18 ns. The dashed column is the fifth cycle, in which every stop holds a different instruction — a vertical slice of the diagram is "what is each resource doing now", a row is "the life of one instruction".

Latency and throughput

Pipelining changes nothing about one instruction. Latency, the time from the fetch of an instruction to its write-back, is still five stages, 10 ns (p. 14: "does not change"). What changes is the throughput: the number of instructions completed per unit of time. One per 10 ns becomes one per 2 ns once the line is full. The notes call pipelining a technique (p. 8), and that is the right word: it is a property of the implementation, not of the instruction set — the program cannot tell whether it runs on a pipeline, it only finishes sooner.

The table is the exam's way of writing Fig. 2: rows are instructions, columns are clock cycles C1, C2 …, and each cell names the stage. (The notes' Table 1 on p. 15 is the transpose, rows for cycles and columns for stages; same diagonal.)

The five instructions of the loop on the ideal pipeline, 2 ns per cycle. I0 finishes in C5, after 10 ns; the last instruction finishes in C9, after 18 ns.
C1C2C3C4C5C6C7C8C9
I0 LD F2, 0(R1)IFIDEXMEMWB
I1 FADD F4, F2, F0IFIDEXMEMWB
I2 SD F4, 0(R1)IFIDEXMEMWB
I3 ADDUI R1, R1, 8IFIDEXMEMWB
I4 BNE R1, R2, LOOPIFIDEXMEMWB

One honesty note. This table assumes what the notes assume for the ideal case: that no instruction needs a value a previous one has not yet produced, and that the branch does not disturb the fetching. Our loop breaks both — FADD needs the F2 that LD produces, and BNE jumps. Lesson 2 and lesson 4 charge for that. Today the pipeline is ideal.

The formula behind the 18 ns

Count cycles in the table. The first instruction needs five; every later one finishes one cycle after its predecessor. Write \(k\) for the number of stages, \(n\) for the number of instructions and \(T\) for the stage time (which is the clock period):

  1. Without a pipeline every instruction takes all \(k\) stage times, one after another:

    \[ T_{\text{seq}} = n \, k \, T . \]
  2. On the pipeline the first instruction finishes in cycle \(k\). Instruction number \(i\) (counting from 1) enters one cycle later than its predecessor and therefore finishes one cycle later: in cycle \(k + (i - 1)\).

  3. The last instruction has \(i = n\), so the whole program ends in cycle \(k + n - 1\):

    \[ T_{\text{pipe}} = (k + n - 1) \, T . \]

    With \(k = 5\), \(n = 5\), \(T = 2\) ns: \(9 \times 2 = 18\) ns, the number of the hook. The \(k - 1 = 4\) extra cycles are the fill: the cycles before the first instruction comes out, during which the stops behind it are still filling up.

  4. The speedup is the ratio; the stage time cancels:

    \[ S(n) = \frac{n \, k \, T}{(k + n - 1) \, T} = \frac{n \, k}{k + n - 1} . \]
  5. Divide numerator and denominator by \(n\). As \(n\) grows, \((k - 1) / n\) vanishes and the speedup climbs towards \(k\) — never reaching it:

    \[ S(n) = \frac{k}{1 + (k - 1)/n} \;\longrightarrow\; k . \]

    For five instructions: \(25 / 9 = 2.78\). For a hundred: \(500 / 104 = 4.81\).

Ideal five-stage pipeline, 2 ns per stage: time and speedup for \(n\) instructions, recomputed from \((k + n - 1)\,T\).
\(n\)sequential \(10n\) nspipelined \((n + 4) \times 2\) nsspeedup
110101.00
550182.78
10100283.57
20200484.17
10010002084.81
100010 00020084.98

Sequential against pipelined: where the 5× hides

The upper chart is Fig. 2 drawn to scale for your own \(n\) and \(k\): every instruction's stages against time. The lower chart is the speedup \(S(n)\) with the ceiling \(k\). The work of one instruction is fixed at 10 ns and split evenly over the \(k\) stages; the overhead slider adds a pipeline-register delay to every stage.

  1. Before touching anything, predict: with the notes' values (five instructions, five stages, no overhead) the sequential run takes 50 ns. What will the total time and the speedup read when you switch on "pipelined execution"?
    What you should see

    18 ns and 2.78×. The orange band at the left is the fill, four cycles in which the stops behind the first instruction are still empty; those 8 ns are the gap between 2.78 and 5.

  2. Keep the pipeline on and raise \(n\) to 20. Predict the speedup before you look, then check the point on the lower chart.
    What you should see

    4.17×: \(200 / 48\). The fill is still four cycles, but now it is spread over twenty instructions. The curve creeps towards the dashed ceiling \(k = 5\) and never touches it.

  3. Set the register overhead to 0.5 ns per stage with \(k = 5\). The ceiling readout changes. Why to exactly 4?
    What you should see

    The clock period is now 2 + 0.5 = 2.5 ns, so a full pipeline completes one instruction per 2.5 ns against one per 10 ns sequentially: 10 / 2.5 = 4. The overhead lowers the ceiling for every \(n\); the magenta curve sits below the teal one.

  4. Keep 0.5 ns of overhead and go to \(k = 10\). Is a ten-stage pipeline twice as good as a five-stage one?
    What you should see

    No: the ceiling is 10 / (1 + 0.5) = 6.67, not 10. At 1 ns of overhead per stage it falls to 5, the same as a five-stage pipeline with no overhead at all. The one insight to take away: the clock period is the slowest stage plus the register overhead, so deeper pipelines pay a growing tax.

Why not ten stages of 1 ns, then twenty of 0.5 ns?

Because the clock period is not "the work divided by \(k\)". Every stage ends in a pipeline register (next section), and that register costs time on every cycle: setup, delay, the uncertainty of the clock edge. The clock period must be at least the delay of the slowest stage plus this overhead, \(T_{\text{clk}} \ge \max_i d_i + t_{\text{reg}}\). Split 10 ns into 10 stages with 0.5 ns of overhead each and the clock is 1.5 ns, not 1 ns; the ceiling is 6.67, not 10. Stages are never perfectly balanced either, so the slowest sets the pace for all, and a deeper pipeline has more instructions in flight, so every hazard of the next lessons costs more cycles. This argument is Hennessy and Patterson's, not the notes': it is the standard answer to "why deeper is not always faster".

Pipelining raises throughput, not speed: one instruction still takes \(k\) cycles, but once the line is full one completes every cycle, and \(n\) instructions take \(k + n - 1\) cycles.

What each instruction does at each stop

All five instructions march through the same five stages, but they do different things there — and in some stages nothing at all. The notes give one small table per instruction class (pp. 16–17); here they are side by side, in the loop's own instructions. The cell marked "born" is where the instruction's result first exists; the cell marked "idle" is a stage the instruction passes through without doing anything.

Stage by stage, for the four kinds of instruction in the loop. A value is "born" at the end of the cycle shown.
InstructionIFIDEXMEMWB
LD F2, 0(R1)
load
fetch; PC + 4read R1; extract 0address R1 + 0read memory — F2 bornwrite F2
FADD F4, F2, F0
ALU
fetch; PC + 4read F2, F0F2 + F0 — F4 bornidle: passes throughwrite F4
SD F4, 0(R1)
store
fetch; PC + 4read R1 and F4address R1 + 0write F4 to memoryidle: nothing to write
ADDUI R1, R1, 8
ALU, immediate
fetch; PC + 4read R1; extract 8R1 + 8 — R1 bornidle: passes throughwrite R1
BNE R1, R2, LOOP
branch
fetch; PC + 4read R1, R2compare R1 with R2; target = PC + offsetload the PC if takenidle: no register to write

Three facts in this table are worth more than the rest, because the next lessons are built on them. A load's value is born at the end of MEM, one stage later than an ALU result, because the load needs the ALU for the address and then the memory: this is why a load's consumer will cost a stall that no wire can remove. A store reads two registers in ID — the base and the data — although the data is needed only in MEM: ID is the only stage with read ports, so the value is read early and carried along. And a branch compares in EX and loads the PC in MEM; the instructions fetched meanwhile were fetched blind. That is the control hazard the notes name on p. 17 and lesson 4 is about.

IF ID EX ME WB LD F2, 0(R1) IF ID EX ME WB FADD F4, F2, F0 IF ID EX ME WB SD F4, 0(R1) IF ID EX ME WB ADDUI R1, R1, 8 IF ID EX ME WB BNE R1, R2, LOOP IF ID EX ME WB F2 born in ME idle, not skipped
Fig. 3. The yellow cells are where a result is born: EX for an ALU instruction, MEM for a load. The grey cells are stages the instruction does nothing in. Every row still has five cells: an idle stage is traversed, never skipped.

Why an idle stage is not a skipped stage

Look at the grey cells and ask the obvious question: the FADD has its result at the end of EX, so why not write it in the very next cycle and let the instruction leave the pipeline early? Because of the fifth column of Fig. 1. The register file has one write port, and in any cycle the instruction one step ahead may be using it. If FADD jumped from EX to WB, it would reach WB in cycle 5, the same cycle as the LD in front of it — two writes, one port. Worse, an ALU instruction that follows a load would then write its register before the load writes its own, and results would land in the register file out of program order. Keeping every instruction in the pipe for exactly five cycles guarantees that at most one instruction is in WB per cycle and that writes happen in order. The idle stage is the price of that guarantee, and the price is zero: the stage was going to exist anyway.

One last look at the table before moving on. F2 is born at the end of cycle 4, in the LD's MEM stage — but FADD reads F2 in its ID stage, which is cycle 3. The ideal table of the previous section quietly reads a value that does not exist yet. That is the data hazard, and what the hardware does about it is the whole of lesson 2.

An ALU result is born at the end of EX, a loaded value at the end of MEM; an instruction with nothing to do in a stage still spends the cycle there.

What travels between the stops: the pipeline registers

Between any two stations of a car factory there is a short stretch of conveyor that holds the car — and its work order — while the next station is busy. The pipeline has the same thing between any two stages: a pipeline register, a bank of flip-flops that is written at the end of every clock cycle and read in the next. There are four of them, named after the stages they separate: IF/ID, ID/EX, EX/MEM and MEM/WB (notes, p. 19 and Fig. 4 on p. 18). All four are clocked together, so on every clock edge the whole pipeline advances by one stop.

What must a register hold? Everything the instruction inside it still needs for the stages ahead — because the instruction word itself stays behind in IF/ID and is overwritten by the next fetch one cycle later. The notes list the contents in one line each; here is the full list, with the control-signal names of Patterson and Hennessy, which the notes do not spell out:

Two things travel in every register and are easy to forget at the exam: the destination register number and the control bits. Decoding happens once, in ID; from then on the instruction carries its own work order, and each stage consumes the part addressed to it, so the control word gets shorter from register to register. The write-back stage, three cycles after decode, learns which register to write from the rd field of MEM/WB, not from the instruction word, which by then belongs to an instruction three places behind.

IF/ID instruction PC + 4 ID/EX PC + 4 rs1 value rs2 value immediate rd EX control MEM control WB control EX/MEM ALU result store data target, zero rd MEM control WB control MEM/WB memory data ALU result rd WB control rd travels with the instruction control bits are used up stage by stage
Fig. 4. The four pipeline registers as columns of fields. The violet fields are bookkeeping: the destination number rd and the control signals, decoded once in ID and carried along. ID/EX holds control for three stages, EX/MEM for two, MEM/WB for one.

Why have the registers at all? Not for the reason the notes give on p. 19 ("they eliminate the need for re-fetching or re-decoding instructions at each cycle" — re-fetching was never on the table). The real reason is the clock. Without a register between two stages, their logic would form one long combinational path, and the clock period would have to cover both; the register cuts the path, so that the period only has to cover one stage. That is what lets the clock run at the pace of a stage instead of the pace of an instruction, which is the entire point of the technique. The registers are also where the forwarding hardware of the next lesson reads its values from: a result that sits in EX/MEM can be handed to the ALU without waiting for WB.

Datapath walker: five instructions, nine cycles, four registers

The upper row is the datapath of Fig. 1 with the four pipeline registers between the stops; the lower part is the exam-style table. Move the cycle slider, or step with the buttons. Click a pipeline register (or choose it in the list) and the note under the controls tells you what it holds in this cycle — for the instruction that is reading it. Greyed stops are idle.

  1. Before you move anything: in cycle 4, which instruction is in MEM and what does it do there? Then set the slider to C4 and check.
    What you should see

    I0 LD reads the data memory at R1 + 0; the value of F2 is born at the end of this cycle. Go to C5 and inspect MEM/WB: there it is, travelling with rd = F2 and RegWrite = 1, so that WB knows what to write and where.

  2. Set C5, the cycle in which all five stops are occupied. Predict which stop is greyed, then look.
    What you should see

    MEM: it holds I1 FADD, which has no memory access. Choose EX/MEM in the list and the note explains why it does not jump ahead to WB — I0 is writing F2 there in this very cycle, through the single write port.

  3. Inspect ID/EX in C3, then EX/MEM in C4, then MEM/WB in C5. Which field is in all three?
    What you should see

    The destination rd = F2 of the load, and its WB control bits. The instruction word that named F2 was in IF/ID only during C2; from then on the number travels with the instruction. This is the one insight of the widget: rd and the control signals move through the pipeline registers with the instruction they belong to.

  4. Go to C9, the last cycle. How many stops are busy, and what happened to the other four?
    What you should see

    Only WB, with I4 BNE — which has nothing to write there. The four empty stops are the mirror image of the fill: C1 to C4 fill the line, C6 to C9 drain it. Both ends cost the same four cycles, and a program pays them once.

The instruction word stays in IF/ID for one cycle; everything the later stages need — operands, immediate, destination number, control bits — travels with the instruction through ID/EX, EX/MEM and MEM/WB.

The puzzle, solved — and what spoils the ideal line

Back to the hook. Five instructions, 50 ns sequential, 18 ns pipelined, and the notes' "5×". You now have the subtraction: the pipeline needs \(k + n - 1 = 9\) cycles, not \(n = 5\), because the first instruction must travel the whole line before anything comes out — four fill cycles, \(k - 1\). The speedup is \(nk / (k + n - 1) = 25/9 = 2.78\). You get the rest back only by amortising the fill: 100 instructions give 4.81, 1000 give 4.98, and the 5 is a ceiling, approached and never reached. Add the register overhead and the ceiling itself drops below 5.

The same four cycles appear on the example A4 formula sheet the course page shows as "Clock Cycles = IC + Stall Cycles + 4". The "+4" is this fill, counted once per program; the "stall cycles" are the price of what this lesson assumed away. Lesson 3 turns these into CPI and MIPS.

Three things spoil the ideal line, and the notes name them on pp. 10, 17 and 20–21. A structural hazard: two instructions need the same resource in the same cycle — with one memory for instructions and data, the IF of one instruction and the MEM of another would collide, which is why the datapath has two. A data hazard: an instruction needs a value an earlier one has not produced yet — our FADD and its F2. A control hazard: the next PC is not known when the next fetch should start — our BNE. Each of them costs cycles, each has a fix, and each fix is a lesson: data hazards and forwarding next, branches in lesson 4, the hazards that return with multi-cycle units in lesson 7.

One rule to carry with you until lesson 7, where exceptions are treated: whatever overlapping the pipeline does, an exception must look as if the faulting instruction had executed alone — everything before it completed, nothing after it started. Overlap is allowed to change timing, never meaning.

Exam-style questions

Explain the main concepts and benefits of each one of the following techniques used by a pipelined RISC-V processor:

  1. Pipelining of the instruction execution
  2. The five-stage organisation IF / ID / EX / MEM / WB
  3. The pipeline registers
  4. Separate instruction and data memories
Show model answer

1. Pipelining is an implementation technique that overlaps the execution of consecutive instructions: the execution is divided into stages and each stage works on a different instruction in the same clock cycle. The latency of one instruction does not change (k cycles), but once the pipeline is full one instruction completes per cycle, so the throughput grows by up to k times; n instructions take k + n − 1 cycles instead of nk, and the clock period becomes the time of one stage instead of a whole instruction. Costs: a fill of k − 1 cycles, pipeline-register overhead, and hazards (structural, data, control) that insert stalls.

2. The five stages correspond to five resources used once by every instruction: IF fetches from the instruction memory and computes PC + 4; ID decodes and reads the two source registers (two read ports); EX uses the ALU for the operation, the address or the branch comparison; MEM accesses the data memory (loads and stores only); WB writes the destination register (one write port). Because each stage uses a different resource, five instructions can be in flight without conflicts; every instruction traverses all five stages (idle stages are not skipped), so completion is in order and at most one instruction writes per cycle.

3. The pipeline registers IF/ID, ID/EX, EX/MEM and MEM/WB sit between the stages and are written on every clock edge. They hold everything an in-flight instruction still needs: the instruction and PC + 4 (IF/ID); the operand values, the immediate, the destination register number and the control signals for EX, MEM and WB (ID/EX); the ALU result or address, the store data, the branch target, rd and the MEM/WB control (EX/MEM); the loaded data or ALU result, rd and the WB control (MEM/WB). Benefits: they isolate the stages so that the clock period equals one stage; the control is decoded once and carried along; and they are the source of the values used by forwarding.

4. With a single memory, the instruction fetch of one instruction and the data access of another (IF and MEM of two different instructions in the same cycle) would compete for the memory port: a structural hazard with a stall every time. Separate instruction and data memories (in practice separate L1 caches) give the two stages their own port, so the hazard is designed away. It is a property of the implementation, not of the instruction set.

The 2026 paper asks its 8-point question in exactly this form: "Explain the main concepts and benefits of each one of the following techniques", with a few lines per sub-point. Fill them with the key words — overlap, throughput versus latency, k + n − 1, one resource per stage, the four register names with their contents, "structural hazard" for the memory — and with a cost next to each benefit. A sub-point that only says what the thing is called says nothing.

Consider the five-stage RISC-V pipeline (IF, ID, EX, MEM, WB) with one clock cycle per stage and no hazards (ideal case). Complete the pipeline diagram for one iteration of the following loop, then give the total number of clock cycles and the execution time with a 2 ns clock. How many cycles would the same five instructions take on a non-pipelined machine that executes the five stages one after another?

LOOP:  LD    F2, 0(R1)
       FADD  F4, F2, F0
       SD    F4, 0(R1)
       ADDUI R1, R1, 8
       BNE   R1, R2, LOOP
Show model answer
C1C2C3C4C5C6C7C8C9
I0 LD F2, 0(R1)IFIDEXMEMWB
I1 FADD F4, F2, F0IFIDEXMEMWB
I2 SD F4, 0(R1)IFIDEXMEMWB
I3 ADDUI R1, R1, 8IFIDEXMEMWB
I4 BNE R1, R2, LOOPIFIDEXMEMWB

Total clock cycles = k + n − 1 = 5 + 5 − 1 = 9 (equivalently IC + 4 = 5 + 4 with no stalls); execution time = 9 × 2 ns = 18 ns. Non-pipelined: 5 × 5 = 25 cycles = 50 ns. Speedup of the pipeline = 50 / 18 = 2.78.

Every row has all five stages, the idle ones included — a row that stops at EX for the FADD or at MEM for the SD is wrong. The diagonal must shift by exactly one column per instruction, and the cycle count must be read from the last WB (C9), not guessed as "5 instructions, 5 cycles".

An ideal five-stage pipeline with a 2 ns clock executes 100 independent instructions. How many nanoseconds does the execution take?

Show model answer
\[ T_{\text{pipe}} = (k + n - 1)\,T \] \[ = (5 + 100 - 1) \times 2 = 208 \text{ ns} \]

Against 1000 ns without the pipeline: a speedup of 1000 / 208 = 4.81.

The tempting wrong answer is 200 ns (one instruction per cycle, no fill). The four extra cycles are the fill of the five-stage pipeline, the "+4" of the course's cycle formula.

A non-pipelined processor executes one instruction in 10 ns. A designer splits that work evenly into 10 pipeline stages, but every stage adds 0.5 ns of pipeline-register overhead to the clock period. What is the maximum speedup over the non-pipelined processor, for a very long program of independent instructions? Give two decimals.

Show model answer

Stage time = 10 / 10 = 1 ns; clock period = 1 + 0.5 = 1.5 ns. For n → ∞ the pipeline completes one instruction per clock period, so the speedup tends to 10 / 1.5 = 6.67 — not 10.

This is the "why deeper is not always faster" question. The expected reasoning is: ceiling = time of one instruction / clock period, and the clock period = slowest stage + register overhead. A five-stage pipeline with the same overhead has a ceiling of 10 / 2.5 = 4, so the deeper pipeline is still better here — but by 1.67×, not 2×.

Which of the following statements about an ideal five-stage pipeline is correct? (Single answer)

  • Each instruction completes in one clock cycle. Each instruction still takes five cycles from fetch to write-back; only the rate of completion changes.
  • Once the pipeline is full, one instruction completes per cycle, but each instruction still takes five cycles. Throughput of one per cycle, latency of five cycles.
  • The latency of each instruction is reduced to one fifth. The latency is unchanged (slightly larger with the register overhead). Pipelining improves throughput, not latency.
  • Five instructions always take exactly five cycles. They take 5 + 5 − 1 = 9 cycles; the first instruction must traverse the whole pipeline before anything completes.
Show model answer

Answer 2. The pipeline overlaps instructions: the time of one instruction is still k cycles, but a new one completes every cycle once the pipeline is full, so n instructions take k + n − 1 cycles.

The quiz tests the latency/throughput distinction — the first bullet of the notes' p. 14. Options 1 and 3 are the same misconception in two forms.

Which of the following statements are true for the basic five-stage RISC-V pipeline? (Multiple answers)

  • An ALU instruction passes through the MEM stage without using it. The stage is traversed idle, so that every instruction keeps a five-cycle latency.
  • A store skips the WB stage and completes one cycle earlier than a load. A store has nothing to write in WB but still spends the cycle there; no stage is skipped.
  • The destination register number travels in the pipeline registers together with the instruction. rd is copied from ID/EX to EX/MEM to MEM/WB, because the instruction word is no longer available when WB happens.
  • The branch updates the PC in the WB stage. The comparison is in EX and the PC is loaded in MEM (basic pipeline); optimised pipelines decide in ID.
  • The value loaded by a load instruction is available only at the end of its MEM stage. EX computes the address, MEM reads the memory; the value does not exist before the end of MEM.
Show model answer

Answers 1, 3 and 5.

Options 2 and 4 are the two claims of the notes corrected in this lesson (pp. 16–17). The 2026 paper uses "Multiple Choice – Multiple answer" quizzes of exactly this shape.

Check yourself

LD F2, 0(R1) is fetched in cycle 1. At the end of which cycle does the value of F2 exist for the first time anywhere in the processor?

  • Cycle 3 In cycle 3 the load is in EX, which only computes the address R1 + 0.
  • Cycle 4 Cycle 4 is the load's MEM stage: the data memory answers, and the word sits in MEM/WB at the end of the cycle.
  • Cycle 5 Cycle 5 is when the value is written into the register file — but it already existed one cycle earlier, in the MEM/WB register. That one cycle is what forwarding exploits in lesson 2.
  • Cycle 2 In cycle 2 the instruction is being decoded; nothing has been read from memory.

A processor executes an instruction in 10 ns. It is pipelined into five stages of 2 ns. The time one instruction spends from its fetch to its write-back becomes…

  • 2 ns 2 ns is the interval between two completions once the pipeline is full — the throughput, not the latency.
  • 10 ns, or a little more The instruction still goes through all the logic; only the overlap with other instructions is new. The register overhead makes it slightly longer, never shorter.
  • 50 ns 50 ns is five instructions one after another.
  • 18 ns 18 ns is the time of five pipelined instructions, not of one.

SD F4, 0(R1) has just finished its ID stage. Which of these are in the ID/EX register at that moment?

  • The value of R1 The base register, read in ID, needed by the ALU in EX.
  • The value of F4 The data to store is read in ID too, although it is needed only in MEM — ID is the only stage with read ports, so it is carried along.
  • The immediate 0 Sign-extended, it is the second ALU operand.
  • The address R1 + 0 The address is computed in EX and appears in EX/MEM, one cycle later.
  • A destination register number that WB will write A store writes no register; its RegWrite control bit is 0.

A picture to keep: ID/EX holds the inputs of EX — two values, an immediate, the destination and the work order — never the result of EX.

Why does FADD not jump from EX straight to WB, skipping the MEM stage in which it has nothing to do?

  • Because the register file has one write port that the instruction ahead may be using in that cycle, and results must be written in program order With a load one place ahead, the two would reach WB in the same cycle. Fixed five-cycle latency keeps one instruction per stage and in-order completion.
  • Because the MEM stage stores the result in memory temporarily An ALU result never touches the data memory; it passes through MEM in the EX/MEM and MEM/WB registers.
  • Because FADD actually reads its operands from memory Its operands are registers, read in ID.
  • It does skip MEM — the notes are right The notes' "skipped" is corrected in this lesson; every instruction traverses all five stages.

A balanced seven-stage pipeline with no overhead and no hazards executes 50 instructions. How many clock cycles does it need?

  • 50 That forgets the fill: the first instruction needs seven cycles before anything completes.
  • 56 k + n − 1 = 7 + 50 − 1 = 56: the fill is k − 1 = 6 cycles, paid once.
  • 57 The fill is k − 1, not k: the first instruction's own seven cycles already include one completion.
  • 350 350 is the non-pipelined count, 50 × 7.

On an ideal five-stage pipeline you double the program from 100 to 200 instructions. The speedup over sequential execution…

  • doubles The speedup is nk / (k + n − 1), which grows ever more slowly: 4.81 becomes 4.90.
  • stays at 4.81 It does grow — the fixed fill of four cycles is now spread over twice as many instructions.
  • rises slightly, towards 5, without reaching it 4.81 → 4.90: the fill becomes a smaller share of the total, and k = 5 is the limit for n → ∞.
  • reaches exactly 5 5 would require zero fill, i.e. no first instruction. It is a ceiling, not a value.

The exam paper writes ADDUI R1, R1, 8. Which instruction of the notes' RISC-V subset does the same thing?

  • add x1, x1, x8 That adds two registers; the 8 of the paper is a constant, not a register.
  • addi x1, x1, 8 Register plus immediate constant: the pointer moves on by 8 bytes.
  • ld x1, 8(x1) That loads from memory at x1 + 8; ADDUI touches no memory.
  • sd x1, 8(x1) That stores to memory; ADDUI only updates a register.

Key take-aways

What to watch and read