THE HAZARD DETECTION UNIT
(a)
IF/ID .Register Rs and IF/ID .Register Rt,the source register for the current instruction
ID/EX.MemRead and ID/EX.RegisterRt, to determine if previous instruction is LW and if so, which register it will write to
--> two new control signals PCWrite and IF/ID write------> determines whether the pipeline stalls or continues
----> A mux select for a new multiplexer , which forces control signals for the current EX and future MEM/WB stages to 0 in case of a stall
sub2,1,3
and12,2,5
or 13,6,2
add 14,2,2
sw 15,100(2)
e.g ID/EX.RegisterRs = register number for Rs sitting in ID/EX pipeline register
ID/EX.RegisterRs, ID/EX.Register Rt
EX/MEM.RegisterRd = ID/EX.RegisterRs
EX/MEM.RegisterRd = ID/EX.RegisterRt
MEM/WB.RegisterRd = ID/EX.RegisterRs
MEM/WB.RegisterRd = ID/EX.RegisterRt
EX/MEM.RegWrite, MEM/WB.RegWrite,
EX/MEM.RegisterRd 0
MEM/WB.RegisterRd 0
----> if (EX/MEM.Reg Write and ( EX/MEM.RegisterRd 0)
and (Ex/MEM.registerRd =ID/EX .RegisterRs))
ForwardA= 10
------> if (EX/MEM.Reg Write and ( EX/MEM.RegisterRd 0)
and (Ex/MEM.registerRd =ID/EX .RegisterRt))
ForwardB= 10
----> if (MEM/WB.RegWrite and ( MEM/WB.RegisterRd 0)
and (MEM/WB.registerRd =ID/EX .RegisterRs))
ForwardA= 01
------> if (MEM/WB.RegWrite and ( MEM/WB.RegisterRd 0)
and (MEM/WB.registerRd =ID/EX .RegisterRt))
ForwardB= 01
(b)
lw 2,20(1)
and become nop
and 4,2,5
or 8,2,6
add 9,4,2
(c) NO
another approach is to guess whether or not the branch is taken. if we correct , then there is no problem and the pipeline keeps going at full speed
The figure shows an additional element added to the CPU to deal with hazards: the hazard detectio...
Insert NOP's in the code below to avoid hazards. The diagram of the CPU is given below and the CPU does not have forwarding or a branch prediction unit.
1. Please show only structural hazards. mov [100], [150] mov [200], [250] add [150], [250], r3 sub r3, #5, r4 add r3, #2, r5 div r4, r5, r6 Instruction encoding: instruction op1, op2, result; [xxxx] – memory address; #x – constant; rx – register. 2. Please show only data hazards. mov [100], [150] mov [200], [300] add [100], [150], [300] add [300], #100, [322] add [300], #200, [333] sub [250], [333], [326] 4. Write program (in pseudo assembler code) for...