5.2.7 · D1Processor Datapath & Pipelining

Foundations — Load-use hazard and stalls

1,723 words8 min readBack to topic

Everything in the parent note (Load-use hazard and stalls) rests on a handful of ideas: what a pipeline is, what the five stages do, what a register and memory are, and what cycles and stages mean on a timeline. We build each from zero, in an order where every new symbol only uses words already earned.


1. The clock and the "cycle" — the heartbeat

Before anything moves, we need a drumbeat. A processor has a clock: a signal that ticks on and off, on and off, forever, at a steady rate.

The picture: think of a metronome. Every "tick" = one cycle. Nothing in the processor moves between ticks; work is snapped forward exactly on each tick.

Why the topic needs it: the whole load-use hazard story is a story about timing — "the data is ready at the end of cycle 4 but is needed at the start of cycle 4." The word "cycle" is the ruler we measure everything against.


2. Registers and memory — two places data can live

Data has to be somewhere. There are two somewheres, and the difference between them is the beating heart of this whole topic.

The picture: a register is a pen already in your hand; memory is a book on a shelf across the room. Grabbing the pen is instant; walking to the shelf costs time.

Why the topic needs it: a load (lw) is exactly the act of walking to the shelf (memory) and bringing a value back into your hand (a register). Because the shelf is far, the value arrives late — and that lateness is the hazard.

See Memory hierarchy and cache for why memory is slow in the first place, and Pipeline control signals for how the processor is told which box to touch.


3. An instruction and its register fields — Rs, Rt, Rd

An instruction is one command, like "add these two numbers" or "load this value." Each instruction names the registers it touches. Three names appear again and again:

Why the topic needs it: a hazard is detected by comparing register names: "does the next instruction read the same register this load is about to fill?" Those names are Rs, Rt, Rd. Full detail lives in Hazard detection unit.


4. The five stages — the five workstations

Every MIPS instruction is broken into five smaller jobs, done in order. This is the Five-stage MIPS pipeline.

The picture: an instruction is a car on an assembly line moving through five workstations, left to right, one station per cycle.

Why the topic needs it: the load's value is produced in MEM and a following add needs it in EX. The whole hazard is "MEM finishes after EX starts." You cannot see that unless you know which stage does what.


5. Pipelining — overlapping the instructions

One instruction alone would waste four stations at any moment. So we pipeline: start a new instruction every cycle, each one step behind the last.

The picture below is the key diagram of the whole chapter — read the diagonal: instruction 2 always trails instruction 1 by exactly one cycle.

Why the topic needs it: because instructions run at the same time, one instruction's result may not be finished when the next one wants it. That overlap is what creates the possibility of a hazard.


6. Data dependency and the hazard

The picture: two workers reaching for the same tool at the same instant, but the tool is still being fetched from the shelf.


7. Forwarding vs. stalling — the two rescues


The prerequisite map

Clock cycle - the tick

Five stages IF ID EX MEM WB

Registers - fast boxes

Instruction fields Rs Rt Rd

Memory - slow shelf

Pipelining - overlap

Data dependency

Load-use hazard

Forwarding

Stall bubble

Each foundation feeds the next: cycles and stages define when things happen, registers and memory define where data lives, pipelining makes them overlap, overlap creates dependencies, and the load's slowness turns one dependency into the hazard that only a stall (plus forwarding) can cure.


Equipment checklist

What is one clock cycle?
The steady time-step between two clock ticks; one step of pipeline work happens per cycle.
Where does register data live vs. memory data?
Registers are tiny fast boxes inside the processor (instant access); memory is large and slow (costs an extra stage to reach).
Why is register \0 special?
It is hardwired to zero, so "writing" it changes nothing and never creates a real dependency.
Name the five stages in order.
IF, ID, EX, MEM, WB (Fetch, Decode, Execute, Memory, Write-back).
For lw $2, 20($1), which field is \2?
Rt — for a load, Rt is the destination register the value lands in.
In which stage does a load produce its value?
MEM (available at the end of the MEM stage).
In which stage does an add need its source values?
EX (at the start of the Execute stage).
What can forwarding NOT do?
Move data backwards in time — it only moves data across space between stages.
Why does one stall plus forwarding fix a load-use hazard?
The stall creates one cycle of delay so the value exists; then forwarding hands MEM/WB data to EX. Without forwarding you'd need two stalls.