235k views
2 votes
Does a five stage MIPS pipeline execution of the following sequence of instructions generate a hazard? If yes, what type of hazard is it? HOW can you resolve it? sub $s0, $t1, $t2 sub $t3, $s0, $t3 sub $t4, $s0, $t4

1 Answer

4 votes
Yes, the given sequence of instructions in a five-stage MIPS pipeline execution does generate a hazard. It is a data hazard known as a RAW (Read After Write) hazard. The hazard occurs because the result of the first instruction (`sub $s0, $t1, $t2`) is required as an input for the second instruction (`sub $t3, $s0, $t3`), and the result of the second instruction is required as an input for the third instruction (`sub $t4, $s0, $t4`).

To resolve this hazard, you can use various techniques:

1. Forwarding: In forwarding, the result of the previous instruction is forwarded directly to the subsequent instruction, bypassing the need to fetch it from the register file. This avoids stalling the pipeline and allows instructions to execute as soon as their required operands are available.

2. Stalling (or bubble): Stalling involves inserting one or more pipeline stages of delay to ensure that the required data is available before proceeding to the subsequent instruction. This effectively pauses the pipeline and gives time for the result of the previous instruction to be written to the register file.

By using one or both of these techniques, the RAW hazard can be resolved, allowing the instructions to execute correctly in the pipeline without any data dependency issues.
User Rajib Biswas
by
8.5k points