Detailed Notes On Data Hazards, Structural Hazards, and Control Hazards
Detailed Notes On Data Hazards, Structural Hazards, and Control Hazards
Abstract
This document provides comprehensive notes on the topics of data hazards, structural
hazards, and control hazards, which are critical concepts in computer architecture and
instruction pipelining. It includes detailed explanations, examples, and techniques for
identifying different types of data hazards. Additionally, it presents important questions and
answers that may be relevant for examination purposes.
1. Data Hazards
Data hazards occur when instructions that depend on the results of prior instructions are
executed in a pipeline. There are three main types of data hazards: Read After Write (RAW),
Write After Read (WAR), and Write After Write (WAW).
• Write After Read (WAR): This occurs when an instruction writes to a location before a
previous instruction has read from it.
• Example:
MOV R1, R2 ; R1 = R2
ADD R2, R3, R4 ; R2 = R3 + R4 (WAR hazard because R1 is read before R2 is
written)
• Write After Write (WAW): This occurs when two instructions write to the same
location, and the order of writes is important.
• Example:
MOV R1, R2 ; R1 = R2
MOV R1, R3 ; R1 = R3 (WAW hazard because the final value of R1 depends on
the order)
2. Structural Hazards
Structural hazards occur when hardware resources are insufficient to support all concurrent
operations in a pipeline.
3. Control Hazards
Control hazards arise from the pipelining of branches and other instructions that change the
program counter (PC).
Q2: Explain the difference between RAW, WAR, and WAW hazards.
A2:
• RAW (Read After Write): An instruction reads a value before it is written by a previous
instruction.
• WAR (Write After Read): An instruction writes to a location before a previous
instruction reads from it.
• WAW (Write After Write): Two instructions write to the same location, and the order
of writes matters.
By understanding these concepts and examples, students can effectively prepare for exams
on data hazards, structural hazards, and control hazards in computer architecture.