-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmips.v
321 lines (275 loc) · 10.8 KB
/
mips.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 20:34:06 12/04/2015
// Design Name:
// Module Name: mips
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module mips(
input rst,
input clk,
input wire[31:0] ins_input,
output wire[31:0] addr_output,
input wire[31:0] ram_data,
output wire[31:0] ram_addr_output,
output wire ram_write_enabler_output,
output wire[3:0] ram_select_output,
output wire[31:0] ram_data_output,
output wire ram_enabler
);
/* PC -> insDecode */
wire [31:0] pc;
wire [31:0] insDecode_PC;
wire [31:0] insDecode_Inst;
/* insDecode -> insDecode2execute */
wire [7:0] insDecode_AluopOutput;
wire [2:0] insDecode_AluselOutput;
wire [31:0] insDecode_Reg1;
wire [31:0] insDecode_Reg2;
wire [4:0] insDecode_DestAddr;
wire insDecode_WriteOrNot;
/* InsDecode -> Regfile & Regfile -> InsDecode*/
wire reg1Enabler;
wire reg2Enabler;
wire [31:0] reg1Data;
wire [31:0] reg2Data;
wire [4:0] reg1Addr;
wire [4:0] reg2Addr;
/* InsDecode -> InsDecode2execute */
wire [7:0] InsDecode_Aluop;
wire [2:0] InsDecode_Alusel;
wire [31:0] InsDecode_Reg1;
wire [31:0] InsDecode_Reg2;
wire [4:0]InsDecode_DestAddr;
wire InsDecode_WriteOrNot;
/* InsDecode2execute -> execute */
wire [7:0] InsDecode2execute_aluop;
wire [2:0] InsDecode2execute_alusel;
wire [31:0] InsDecode2execute_Reg1;
wire [31:0] InsDecode2execute_Reg2;
wire InsDecode2execute_WriteOrNot;
wire [4:0] InsDecode2execute_DestAddr;
/* execute -> execute2memory */
wire execute_WriteOrNot;
wire [4:0] execute_DestAddr;
wire [31:0] execute_Wdata;
wire execute_HILO_enabler;
wire [31:0]execute_HILO_HI;
wire [31:0]execute_HILO_LO;
/* execute2memory -> memory */
wire execute2memory_WriteOrNot;
wire [4:0] execute2memory_DestAddr;
wire [31:0] execute2memory_Wdata;
wire execute2memory_HILO_enabler;
wire [31:0] execute2memory_HILO_HI;
wire [31:0] execute2memory_HILO_LO;
/* memory -> memory2writeback */
wire memory_WriteOrNot;
wire [4:0] memory_DestAddr;
wire [31:0] memory_Wdata;
wire memory_HILO_enabler;
wire [31:0] memory_HILO_HI;
wire [31:0] memory_HILO_LO;
/* memory2writeback -> regfile */
wire memory2writeback_WriteOrNot;
wire [4:0] memory2writeback_DestAddr;
wire [31:0] memory2writeback_Wdata;
/* memory2writeback -> hilo & execute*/
wire memory2writeback_HILO_enabler;
wire [31:0] memory2writeback_HILO_HI;
wire [31:0] memory2writeback_HILO_LO;
/* hilo -> execute */
wire [31:0] hilo_HI;
wire [31:0] hilo_LO;
/* JUMP & BRANCH */
wire [31:0] insDecode2pc_branchTargetAddr;
wire insDecode2pc_branchFlag;
wire [31:0] insDecode_retAddr;
wire insDecode_inDelayslot;
wire insDecode_nextDelay;
wire insDecode2execute_executeInDelayslot;
wire [31:0] insDecode2execute_retAddr;
wire insDecode2execute_insDecodeInDelayslot;
wire [31:0] insDecode_ins;
wire [31:0] insDecode2execute_ins;
wire [7:0] execute_aluop;
wire [31:0] execute_mem_addr;
wire [31:0] execute_regOp2;
wire [7:0] execute2memory_aluop;
wire [31:0] execute2memory_mem_addr;
wire [31:0] execute2memory_regOp2;
wire [5:0] control_output;
wire insDecode_pause;
wire execute_pause;
assign addr_output = pc;
pc_module pc_module0(
.clk(clk),
.rst(rst),
.branch_flag(insDecode2pc_branchFlag),
.branch_target(insDecode2pc_branchTargetAddr),
.pc(pc),
.ce(enabler_output),
.control(control_output)
);
insFetch2insDecode insFecth2insDecode0(
.clk(clk),.rst(rst),
.insFetchPC(pc),.insFetchInst(ins_input),
.insDecodePC(insDecode_PC), .insDecodeInst(insDecode_Inst),
.control(control_output)
);
insDecode insDecode0(
.rst(rst),
.insDecode_pc(insDecode_PC), .insDecode_ins(insDecode_Inst),
.reg1_data_input(reg1Data), .reg2_data_input(reg2Data),
.reg1_read_enabler(reg1Enabler), .reg2_read_enabler(reg2Enabler),
.execute_WriteOrNot(execute_WriteOrNot), .execute_DestAddr(execute_DestAddr), .execute_Wdata,
.memory_WriteOrNot(memory_WriteOrNot), .memory_DestAddr(memory_DestAddr), .memory_Wdata(memory_Wdata),
.reg1_addr_output(reg1Addr), .reg2_addr_output(reg2Addr),
.aluop_output(InsDecode_Aluop), .alusel_output(InsDecode_Alusel),
.regOp1(InsDecode_Reg1), .regOp2(InsDecode_Reg2),
.dest_addr(InsDecode_DestAddr), .write_or_not(InsDecode_WriteOrNot),
.in_delayslot(insDecode2execute_insDecodeInDelayslot),
.branch_flag_output(insDecode2pc_branchFlag),
.branch_target_output(insDecode2pc_branchTargetAddr),
.ret_addr(insDecode_retAddr), .next_delay(insDecode_nextDelay),
.in_delayslot_output(insDecode_inDelayslot),
.insDecode_ins_output(insDecode_ins),
.insDecode_pause_output(insDecode_pause)
);
insDecode2execute insDecode2execute0(
.clk(clk), .rst(rst),
.aluop_input(InsDecode_Aluop), .alusel_input(InsDecode_Alusel),
.regOp1(InsDecode_Reg1), .regOp2(InsDecode_Reg2),
.dest_addr(InsDecode_DestAddr), .write_or_not(InsDecode_WriteOrNot),
.aluop_output(InsDecode2execute_aluop), .alusel_output(InsDecode2execute_alusel),
.regOp1_output(InsDecode2execute_Reg1), .regOp2_output(InsDecode2execute_Reg2),
.dest_addr_output(InsDecode2execute_DestAddr), .write_or_not_output(InsDecode2execute_WriteOrNot),
.in_delayslot(insDecode_inDelayslot), .ret_addr(insDecode_retAddr), .next_delay(insDecode_nextDelay),
.execute_in_delayslot(insDecode2execute_executeInDelayslot),
.ret_addr_output(insDecode2execute_retAddr),
.insDecode_in_delayslot(insDecode2execute_insDecodeInDelayslot),
.insDecode_ins(insDecode_ins),
.insDecode2execute_ins(insDecode2execute_ins),
.control(control_output)
);
execute execute0(
.rst(rst),
.aluop_input(InsDecode2execute_aluop),
.alusel_input(InsDecode2execute_alusel),
.regOp1(InsDecode2execute_Reg1),
.regOp2(InsDecode2execute_Reg2),
.dest_addr(InsDecode2execute_DestAddr),
.write_or_not(InsDecode2execute_WriteOrNot),
.memory_HILO_enabler(memory_HILO_enabler),
.memory_HILO_HI(memory_HILO_HI),
.memory_HILO_LO(memory_HILO_LO),
.hilo0_HILO_HI(hilo_HI),
.hilo0_HILO_LO(hilo_LO),
.dest_addr_output(execute_DestAddr),
.write_or_not_output(execute_WriteOrNot),
.wdata_output(execute_Wdata),
.memory2writeback_HILO_enabler(memory2writeback_HILO_enabler),
.memory2writeback_HILO_HI(memory2writeback_HILO_HI),
.memory2writeback_HILO_LO(memory2writeback_HILO_LO),
.ret_addr(insDecode2execute_retAddr),
.in_delayslot(insDecode2execute_executeInDelayslot),
.execute_HILO_enabler(execute_HILO_enabler),
.execute_HILO_HI(execute_HILO_HI),
.execute_HILO_LO(execute_HILO_LO),
.insDecode2execute_ins(insDecode2execute_ins),
.aluop_output(execute_aluop),
.mem_addr_output(execute_mem_addr),
.regOp2_output(execute_regOp2),
.execute_pause_output(execute_pause)
);
execute2memory execute2memory0(
.rst(rst), .clk(clk),
.dest_addr(execute_DestAddr), .write_or_not(execute_WriteOrNot),
.wdata(execute_Wdata),
.execute_HILO_enabler(execute_HILO_enabler),
.execute_HILO_HI(execute_HILO_HI),
.execute_HILO_LO(execute_HILO_LO),
.dest_addr_output(execute2memory_DestAddr), .write_or_not_output(execute2memory_WriteOrNot),
.wdata_output(execute2memory_Wdata),
.execute2memory_HILO_enabler(execute2memory_HILO_enabler),
.execute2memory_HILO_HI(execute2memory_HILO_HI),
.execute2memory_HILO_LO(execute2memory_HILO_LO),
.aluop(execute_aluop),
.mem_addr(execute_mem_addr),
.regOp2(execute_regOp2),
.aluop_output(execute2memory_aluop),
.mem_addr_output(execute2memory_mem_addr),
.regOp2_output(execute2memory_regOp2),
.control(control_output)
);
memory memory0(
.rst(rst),
.dest_addr(execute2memory_DestAddr),
.write_or_not(execute2memory_WriteOrNot),
.wdata(execute2memory_Wdata),
.execute2memory_HILO_enabler(execute2memory_HILO_enabler),
.execute2memory_HILO_HI(execute2memory_HILO_HI),
.execute2memory_HILO_LO(execute2memory_HILO_LO),
.dest_addr_output(memory_DestAddr),
.write_or_not_output(memory_WriteOrNot),
.wdata_output(memory_Wdata),
.memory_HILO_enabler(memory_HILO_enabler),
.memory_HILO_HI(memory_HILO_HI),
.memory_HILO_LO(memory_HILO_LO),
.aluop(execute2memory_aluop),
.mem_addr(execute2memory_mem_addr),
.regOp2(execute2memory_regOp2),
.mem_data(ram_data),
.mem_data_output(ram_data_output),
.mem_addr_output(ram_addr_output),
.mem_write_enabler_output(ram_write_enabler_output),
.mem_select_output(ram_select_output),
.mem_enabler_output(ram_enabler)
);
memory2writeback memory2writeback0(
.clk(clk), .rst(rst),
.dest_addr(memory_DestAddr), .write_or_not(memory_WriteOrNot),
.wdata(memory_Wdata),
.memory_HILO_enabler(memory_HILO_enabler),
.memory_HILO_HI(memory_HILO_HI),
.memory_HILO_LO(memory_HILO_LO),
.dest_addr_output(memory2writeback_DestAddr), .write_or_not_output(memory2writeback_WriteOrNot),
.wdata_output(memory2writeback_Wdata),
.memory2writeback_HILO_enabler(memory2writeback_HILO_enabler),
.memory2writeback_HILO_HI(memory2writeback_HILO_HI),
.memory2writeback_HILO_LO(memory2writeback_HILO_LO),
.control(control_output)
);
regfile regfile0(
.clk(clk), .rst(rst),
.we(memory2writeback_WriteOrNot), .waddr(memory2writeback_DestAddr), .wdata(memory2writeback_Wdata),
.re1(reg1Enabler), .re2(reg2Enabler),
.raddr1(reg1Addr), .raddr2(reg2Addr),
.rdata1(reg1Data), .rdata2(reg2Data)
);
hilo hilo0(
.clk(clk), .rst(rst),
.enabler(memory2writeback_HILO_enabler),
.memory2writeback_HI(memory2writeback_HILO_HI), .memory2writeback_LO(memory2writeback_HILO_LO),
.hilo_hi(hilo_HI), .hilo_lo(hilo_LO)
);
control control0(
.rst(rst),
.insDecode_pause(insDecode_pause),
.execute_pause(execute_pause),
.control_output(control_output)
);
endmodule