-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforwardingUnit.v
39 lines (34 loc) · 1.03 KB
/
forwardingUnit.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
module forwardingUnit(forwardA,forwardB,IDrs,IDrt,EXrd,MEMrd,EXregWrite,MEMregWrite);
output forwardA;
output forwardB;
reg [1:0] forwardA;
reg [1:0] forwardB;
input [4:0]IDrs;
input [4:0]IDrt;
input [4:0] EXrd;
input [4:0]MEMrd;
input EXregWrite;
input MEMregWrite;
//forwardA from ALU to ALU and from MEM to ALU
always@(MEMregWrite or EXregWrite or MEMrd or EXrd or IDrt or IDrs)
begin
if((EXregWrite==1'b1) && (EXrd != 5'b0) && (EXrd==IDrs) )
forwardA <=2'b10;
else if ((MEMregWrite==1'b1) && (MEMrd !=5'b0) && (MEMrd==IDrs) && ((EXregWrite!=1'b1) || (EXrd ==5'b0) || (EXrd!=IDrs)))
forwardA <=2'b01;
else begin
forwardA <=2'b00;
end
end
//forwardA from ALU to ALU and from MEM to ALU
always@(MEMregWrite or EXregWrite or MEMrd or EXrd or IDrt or IDrs)
begin
if((EXregWrite==1'b1) && (EXrd != 5'b0) && (EXrd==IDrt) )
forwardB <=2'b10;
else if ((MEMregWrite==1'b1) && (MEMrd !=5'b0) && (MEMrd==IDrt) && ((EXregWrite!=1'b1) || (EXrd ==5'b0) || (EXrd!=IDrt)))
forwardB <=2'b01;
else begin
forwardB <=2'b00;
end
end
endmodule