Open In App

Data Hazards and its Handling Methods

Last Updated : 13 Nov, 2025
Comments
Improve
Suggest changes
35 Likes
Like
Report

Data hazards occur when an instruction depends on the result of a previous instruction, and that result of the instruction has not yet been computed. whenever two different instructions use the same storage. The location must appear as if it is executed in sequential order. 

data_hazards

There are four types of data dependencies: Read after Write (RAW), Write after Read (WAR), Write after Write (WAW), and Read after Read (RAR). These are explained as follows below. 

Read after Write (RAW):
It is also known as True dependency or Flow dependency. It occurs when the value produced by an instruction is required by a subsequent instruction. For example,

ADD R1, --, --;
SUB --, R1, --;

Stalls are required to handle these hazards. 

Write after Read (WAR) :
It is also known as anti dependency. These hazards occur when the output register of an instruction is used right after read by a previous instruction. For example,

ADD --, R1, --;
SUB R1, --, --;

Write after Write (WAW) : 
It is also known as output dependency. These hazards occur when the output register of an instruction is used for write after written by previous instruction. For example,

ADD R1, --, --;
SUB R1, --, --;

Read after Read (RAR) : 
It occurs when the instruction both read from the same register. For example,

ADD --, R1, --;
SUB --, R1, --;

Since reading a register value does not change the register value, these Read after Read (RAR) hazards don't cause a problem for the processor. 

Data hazards occur when instructions in a pipeline depend on the results of previous instructions. To ensure smooth execution, various hazard-handling techniques like forwarding and stalling are used. provides an in-depth exploration of these techniques, ensuring you're well-prepared for competitive exams and real-world applications

Handling Data Hazards : 
These are various methods we use to handle hazards: Forwarding, Code reordering , and Stall insertion. 

These are explained as follows below. 

  1. Forwarding :
    It adds special circuitry to the pipeline. This method works because it takes less time for the required values to travel through a wire than it does for a pipeline segment to compute its result.
  2. Code reordering :
    We need a special type of software to reorder code. We call this type of software a hardware-dependent compiler.
  3. Stall Insertion :
    it inserts one or more stall (no-op instructions) into the pipeline, which delays the execution of the current instruction until the required operand is written to the register file, but this method decreases pipeline efficiency and throughput.  

Explore