-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforwardingUnit.v
26 lines (26 loc) · 896 Bytes
/
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
module Forwarding(
IDEX_RegRt,
IDEX_RegRs,
EXMEM_RegRd,
MEMWB_RegRd,
EXMEM_RegWrite,
MEMWB_RegWrite,
forwardA,
forwardB
);
//input output
input [4:0] IDEX_RegRt;
input [4:0] IDEX_RegRs;
input [4:0] EXMEM_RegRd;
input [4:0] MEMWB_RegRd;
input EXMEM_RegWrite;
input MEMWB_RegWrite;
output [1:0] forwardA;
output [1:0] forwardB;
//reg & wire
//Combinational part
assign forwardA = (EXMEM_RegWrite && (EXMEM_RegRd != 5'd0) && (EXMEM_RegRd == IDEX_RegRs)) ? 2'b10 :
(MEMWB_RegWrite && (MEMWB_RegRd != 5'd0) && (MEMWB_RegRd == IDEX_RegRs)) ? 2'b01 : 2'b00;
assign forwardB = (EXMEM_RegWrite && (EXMEM_RegRd != 5'd0) && (EXMEM_RegRd == IDEX_RegRt)) ? 2'b10 :
(MEMWB_RegWrite && (MEMWB_RegRd != 5'd0) && (MEMWB_RegRd == IDEX_RegRt)) ? 2'b01 : 2'b00;
endmodule