-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathforwardUnit.v
33 lines (33 loc) · 1.23 KB
/
forwardUnit.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
// Code your design here
module ForwardUnit(MEMRegRd, WBRegRd, EXRegRs,EXRegRt,MEM_RegWrite,WB_RegWrite, load, ForwardA, ForwardB);
input[4:0] MEMRegRd,WBRegRd,EXRegRs,EXRegRt;
input MEM_RegWrite,WB_RegWrite, load;
output[1:0] ForwardA,ForwardB;
reg[1:0] ForwardA,ForwardB;
//Forward A
always@(*)
begin
if ((load && MEM_RegWrite && EXRegRt == MEMRegRd)
|| (load && WB_RegWrite && EXRegRt == WBRegRd))
ForwardA <= 2'b00;
else if ((MEM_RegWrite)&&(MEMRegRd != 0)&&(MEMRegRd== EXRegRs))
ForwardA <= 2'b10;
else if ((WB_RegWrite)&&(WBRegRd != 0)&&(WBRegRd == EXRegRs)&&(MEMRegRd != EXRegRs) )
ForwardA <= 2'b01;
else
ForwardA <= 2'b00;
end
//Forward B
always@(*)
begin
if ((load && MEM_RegWrite && EXRegRt == MEMRegRd)
|| (load && WB_RegWrite && EXRegRt == WBRegRd))
ForwardB = 2'b00;
else if ((WB_RegWrite)&&(WBRegRd != 0)&&(WBRegRd == EXRegRt)&&(MEMRegRd != EXRegRt) )
ForwardB = 2'b01;
else if ((MEM_RegWrite)&&(MEMRegRd != 0)&&(MEMRegRd == EXRegRt))
ForwardB = 2'b10;
else
ForwardB = 2'b00;
end
endmodule