-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathID.v
92 lines (82 loc) · 1.57 KB
/
ID.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// build a module for instruction decode
module ID_Stage
(
clk,
rst,
writedata,
write,
lastDestination,
Instruction_in,
WB_En,
MEM_R_En,
MEM_W_En,
Is_Imm,
BR_Type,
EXE_Cmd,
readdata1,
readdata2,
Immediate,
data1,
data2,
src1,
src2,
dest
);
// input and output ports
input clk;
input rst;
input write;
input [4:0] lastDestination;
input [31:0] writedata;
input [31:0] Instruction_in;
output WB_En;
output MEM_R_En;
output MEM_W_En;
output Is_Imm;
output [1:0] BR_Type;
output [3:0] EXE_Cmd;
output [4:0] src1;
output [4:0] src2;
output [4:0] dest;
output [31:0] readdata1;
output [31:0] readdata2;
output [31:0] Immediate;
output [31:0] data1;
output [31:0] data2;
// build module
// control unit
Controller CU
(
.Opcode(Instruction_in[31:26]),
.Is_Imm(Is_Imm),
.WB_En(WB_En),
.MEM_R_En(MEM_R_En),
.MEM_W_En(MEM_W_En),
.EXE_Cmd(EXE_Cmd),
.BR_Type(BR_Type)
);
// register file
Register_File RF
(
.clk(clk),
.rst(rst),
.readaddress1(src1),
.readaddress2(src2),
.writeaddress(lastDestination),
.writedata(writedata),
.write(write),
.readdata1(readdata1),
.readdata2(readdata2)
);
// sign extend
assign Immediate = {{16{Instruction_in[15]}}, Instruction_in[15:0]};
// data 1 mux
assign data1 = readdata1;
// data 2 mux
assign data2 = (Is_Imm) ? Immediate : readdata2;
// sources
assign src1 = Instruction_in[25:21];
assign src2 = Instruction_in[20:16];
// destination
assign dest = (Is_Imm) ? Instruction_in[20:16] : Instruction_in[15:11];
endmodule