-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathHazardDetectionUnit.v
44 lines (37 loc) · 1.06 KB
/
HazardDetectionUnit.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module HazardDetectionUnit(ID_ExMemRead,EX_MemMemRead,ID_Ex_Rt,IF_ID_Instr,holdPC,holdIF_ID,muxSelector);
input ID_ExMemRead,EX_MemMemRead;
input [4:0] ID_Ex_Rt;
input [31:0] IF_ID_Instr;
output reg holdPC, holdIF_ID, muxSelector;
parameter beqOPcode=6'b000100;
initial
begin
holdPC <= 0;
holdIF_ID <= 0;
muxSelector <= 0;
end
always@(ID_ExMemRead or ID_Ex_Rt or IF_ID_Instr)
begin
if (ID_ExMemRead && (holdPC == 1'b0) && (holdIF_ID == 1'b0))
begin
if(ID_Ex_Rt==IF_ID_Instr[25:21] || ID_Ex_Rt==IF_ID_Instr[20:15] )
begin
holdPC<=1;
holdIF_ID<=1;
muxSelector<=1;
end
end
else if((IF_ID_Instr [31:26]==beqOPcode) && (holdPC == 1'b0) && (holdIF_ID == 1'b0))
begin
holdPC<=1;
holdIF_ID<=1;
muxSelector<=1;
end
else
begin
holdPC<=0;
holdIF_ID<=0;
muxSelector<=0;
end
end
endmodule