2.4Data hazards
The idea
A data hazard is a clash between instructions that use the same register in an order that could give the wrong result if they overlapped.
Think of it like this: A shared notebook: reading a page before your colleague has written it (RAW), or writing over a page before they have read it (WAR).
Why it exists
The pipeline overlaps instructions but the program must behave as if they ran one after another.
How it works
- RAW (read after write): a later instruction reads what an earlier one writes. The only true dependency; the common one.
- WAR (write after read): later writes what earlier reads. Matters with out-of-order execution.
- WAW: both write the same register. Matters with out-of-order completion.
Worked example: I1: ADD R1,R2,R3 I2: SUB R4,R1,R5
I2 reads R1, which I1 writes: RAW.
Now play with it
- →Pick I1 and I2: RAW. Pick I1 and I3: WAW. Pick I2 and I3: WAR. Pick I3 and I4: both RAW and WAR.
Check yourself
I1: ADD R1,R2,R3 I2: SUB R4,R1,R5. Which hazard exists between them?
Exam notes (the dense version)
RAW (true dependency, read after write), the common one. WAR (anti) and WAW (output) arise with out-of-order completion / different write stages.
Previous year questions: Instruction Pipelining & Hazards (15)
PYQs are grouped by topic, so this is the full set for Instruction Pipelining & Hazards; try the ones that match this subtopic. Open all 15 on the topic page.