So this is a question about computer organization Consider following instruciotns:
add $t2, $t2, $t2
nop
nop
add $t2, $t2, $t2
We can draw cycle diagram like:
add| IF| ID|EXE|MEM| WB|
nop| | | | | |
nop| | | | | |
add| | | | IF| ID|EXE|MEM| WB|
first add is in WB stage and second add is in ID stage.
Textbook tell me that this won't make hazard since you can write Registerfile in first half cycle and read it in second half cycle. It doesn't make sence if we assume pipeline stage and registerfile both are positive edge trigger. The behavior can described by verilog like:
always @(posedge clk)begin
if(RegWrite) regfile[waddr] <= wdata;
end
Here is the timing diagram I think: This
As you see when second add is reading registerfile, the new data is just being written. How can you write in first half cycle when RegWrite is "LOW"?
At least there will be a clk to Q delay. It is impossible to write register at positive edge.
If clock phase of pipeline register and registerfile are different, it's not a problem anymore, but no one said that. Or just simply tell me you can read data just being written somehow.
==============================
clk __/‾‾‾\___/‾‾‾\___
RegWrite ____/‾‾‾‾‾‾‾‾\____
there must be a clk to q delay for RegWrtie. how Regfile write data at "clock edge" when RegWrite is LOW?