Question Details

Which one of the following of register operands on different instructions can cause data hazard in the pipelined processor?

Options

A

Write After Read

B

Write After Write

C

Read After Read

D

Read After Write

Show Answer

Correct Answer :

Option D

Read After Write

Solution :

The correct option is Read After Write.

In a pipelined processor, data hazards occur when instructions that are close together in the instruction stream reference the same memory or register operands, and the execution of those instructions overlaps in time. If the pipeline is not stalled or the operands are not forwarded, this overlap can lead to incorrect results.

Let us analyze the nature of data hazards by looking at the relationship between two instructions, where Instruction 1 occurs before Instruction 2 in program order:

1. Read After Write (RAW):
This hazard occurs when Instruction 2 tries to read a source register before Instruction 1 has written to it. In other words, Instruction 2 requires the value produced by Instruction 1. Since Instruction 1's write-back stage occurs late in the pipeline while Instruction 2's decode/read stage occurs early, Instruction 2 might read the old (incorrect) value. This is a true dependency and is the primary cause of data hazards in standard pipelined processors.

2. Write After Read (WAR):
This hazard occurs when Instruction 2 tries to write to a destination register before it is read by Instruction 1. In standard in-order pipelines, this cannot cause a hazard because registers are read in earlier stages (e.g., Instruction Decode) than they are written (e.g., Write Back). Hence, Instruction 1 will always read the register before Instruction 2 writes to it.

3. Write After Write (WAW):
This hazard occurs when Instruction 2 tries to write to a destination register before Instruction 1 writes to it, potentially leaving the register with the older value from Instruction 1 instead of the newer one from Instruction 2. In a standard in-order pipeline, since instructions write back in the order they are issued, this hazard does not occur.

4. Read After Read (RAR):
This situation occurs when both instructions read from the same register. Since reading a register does not modify its state or value, there is no dependency or conflict, and no hazard can occur.

Consequently, in a standard pipelined processor, Read After Write is the register operand relationship that causes a data hazard.

Unlock Our Free Library

Access expert-curated educational resources and study materials—completely free.

Ask AI Tutor
5 left
Q1 View Question & Options
AI Tutor is solving this question...
Reading question context & options...