-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMIPS.v
347 lines (324 loc) · 9.34 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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 00:27:58 11/29/2021
// Design Name:
// Module Name: MIPS
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module MIPS();
//input clock
//);
reg clock =0;
always #10 clock = ~clock;
reg do_not_care = 0;
wire [31:0] jump_signal=$random;
wire [31:0] jump_signal_out=jump_signal;
//------------------------------------------------
// FETCH
//------------------------------------------------
wire [31:0] next_pc_from_fetch;
wire [31:0] instruction_from_fetch;
wire hit_from_fetch;
//assign next_pc_from_fetch = $random;
//------------------------------------------------
// IF_ID (PIPELINE)
//------------------------------------------------
wire [31:0] next_pc_from_IFID;
wire [31:0] instruction_from_IFID;
wire hit_from_IFID;
//------------------------------------------------
// DECODE
//------------------------------------------------
wire [5:0] opcode_form_decode;
wire [31:0] read_data1_form_decode;
wire [31:0] read_data2_form_decode;
wire [31:0] sign_extended_immediate_form_decode;
wire [4:0] rt_form_decode;
wire [4:0] rd_form_decode;
//------------------------------------------------
// CONTROL_UNIT
//------------------------------------------------
wire RegDst_from_controlUnit;
wire ALUSrc_from_controlUnit;
wire MemtoReg_from_controlUnit;
wire RegWrite_from_controlUnit;
wire MemRead_from_controlUnit;
wire MemWrite_from_controlUnit;
wire Branch_from_controlUnit;
wire [5:0] ALUOp_from_controlUnit;
//wire jumpSignal_from_controlUnit;
//------------------------------------------------
// ID_EX (PIPELINE)
//------------------------------------------------
wire [31:0] readData1Out_from_IDEX;
wire [31:0] readData2Out_from_IDEX;
wire [31:0] signExImmediateOut_from_IDEX;
wire RegDstOut_from_IDEX;
wire ALUSrcOut_from_IDEX;
wire MemtoRegOut_from_IDEX;
wire RegWriteOut_from_IDEX;
wire MemReadOut_from_IDEX;
wire MemWriteOut_from_IDEX;
wire BranchOut_from_IDEX;
wire [5:0] ALUOpOut_from_IDEX;
wire [4:0] rtOut_from_IDEX;
wire [4:0] rdOut_from_IDEX;
wire [5:0] functOut_from_IDEX;
wire [31:0] nextPCOut_from_IDEX;
wire hitOut_from_IDEX;
//wire jumpSignalOut_from_IDEX;
//------------------------------------------------
// EXECUTE
//------------------------------------------------
wire [31:0] ALUResult_from_Execute;
wire zero_from_Execute;
//------------------------------------------------
// ALU_MIPS
//------------------------------------------------
wire [31:0] branchTarget_from_alu_mips_m;
//------------------------------------------------
// MULTIPLEXER_MIPS
//------------------------------------------------
wire [4:0] writeRegOut_from_mips_multiplexer;
//------------------------------------------------
// EX_MEM_REGISTER
//------------------------------------------------
wire [31:0] branchTargetOut_from_EM_MEM;
wire zeroFlagOut_from_EM_MEM;
wire [31:0] ALUResultOut_from_EM_MEM;
wire [31:0] readData2Out_from_EM_MEM;
wire [4:0] writeRegOut_from_EM_MEM;
wire MemReadOut_from_EM_MEM;
wire MemWriteOut_from_EM_MEM;
wire BranchOut_from_EM_MEM;
wire RegWriteOut_from_EM_MEM;
wire MemToRegOut_from_EM_MEM;
wire hitOut_from_EM_MEM;
//wire jumpSignalOut_from_EM_MEM;
//------------------------------------------------
// DATA MEMORY
//------------------------------------------------
wire [31:0] readData_from_DataMemory;
//------------------------------------------------
// AND ( EX/MEM -> MEM/WB)
//------------------------------------------------
wire pc_source_from_AND;
//------------------------------------------------
// MEM_WB_REGISTER
//------------------------------------------------
wire hitOut_from_MEM_WB;
wire [31:0] readDataOut_from_MEM_WB;
wire [31:0] ALUResultOut_from_MEM_WB;
wire [4:0] writeRegOut_from_MEM_WB;
wire RegWriteOut_from_MEM_WB;
wire MemtoRegOut_from_MEM_WB;
//------------------------------------------------
// MULTIPLEXER_AFTER_MEM_WB
//------------------------------------------------
wire [31:0] writeDataOut_from_wirte_back;
//------------------------------------------------
wire [5:0] write_reg_MIPS;
wire [5:0] write_data_MIPS;
OpcodeBasedMux2X1 OpcodeBasedMux2X1_m(
RegWrite_from_controlUnit,
opcode_form_decode,
next_pc_from_fetch,
writeRegOut_from_MEM_WB,
writeDataOut_from_wirte_back,
write_reg_MIPS,
write_data_MIPS
);
Fetch fetch_m(
clock,
branchTargetOut_from_EM_MEM,
pc_source_from_AND,
//ALUResultOut_from_EM_MEM,
next_pc_from_fetch,
instruction_from_fetch,
hit_from_fetch
);
IF_ID_Register IDIFRegister_m(
clock,
next_pc_from_fetch,
instruction_from_fetch,
hit_from_fetch,
instruction_from_IFID,
next_pc_from_IFID,
hit_from_IFID
);
Decode decode_m(
clock,
instruction_from_IFID,
RegWrite_from_controlUnit,
write_reg_MIPS,//
wirte_data_MIPS,//
opcode_form_decode,
read_data1_form_decode,
read_data2_form_decode,
sign_extended_immediate_form_decode,
rt_form_decode,
rd_form_decode
);
ControlUnit control_unit_m(
opcode_form_decode,
RegDst_from_controlUnit,
ALUSrc_from_controlUnit,
MemtoReg_from_controlUnit,
RegWrite_from_controlUnit,
MemRead_from_controlUnit,
MemWrite_from_controlUnit,
Branch_from_controlUnit,
ALUOp_from_controlUnit
//jumpSignal_from_controlUnit
);
/*
register31 reg_31_m(
clock,
next_pc_from_IFID,
opcode_form_decode,
register_31_pc
);
*/
ID_EX_Register ID_EX_Register_m(
clock,
hit_from_IFID,
read_data1_form_decode,
read_data2_form_decode,
sign_extended_immediate_form_decode,
RegDst_from_controlUnit,
ALUSrc_from_controlUnit,
MemtoReg_from_controlUnit,
RegWrite_from_controlUnit,
MemRead_from_controlUnit,
MemWrite_from_controlUnit,
Branch_from_controlUnit,
{1'b0, ALUOp_from_controlUnit},
rt_form_decode,
rd_form_decode,
sign_extended_immediate_form_decode[5:0], //funct
next_pc_from_fetch,
jump_signal,
readData1Out_from_IDEX,
readData2Out_from_IDEX,
signExImmediateOut_from_IDEX,
RegDstOut_from_IDEX,
ALUSrcOut_from_IDEX,
MemtoRegOut_from_IDEX,
RegWriteOut_from_IDEX,
MemReadOut_from_IDEX,
MemWriteOut_from_IDEX,
BranchOut_from_IDEX,
ALUOpOut_from_IDEX,
rtOut_from_IDEX,
rdOut_from_IDEX,
functOut_from_IDEX,
nextPCOut_from_IDEX,
hitOut_from_IDEX,
jump_signal_out
);
// ----------------------------------------------------------
// ----------------------------------------------------------
Execute execute_m(
clock,
readData1Out_from_IDEX,
readData2Out_from_IDEX,
signExImmediateOut_from_IDEX,
functOut_from_IDEX,
ALUOpOut_from_IDEX,
ALUSrcOut_from_IDEX,
ALUResult_from_Execute,
zero_from_Execute
);
ALU alu_mips_m(
0,
nextPCOut_from_IDEX,
signExImmediateOut_from_IDEX<<1,
0,
branchTarget_from_alu_mips_m,
do_not_care
);
multiplexer32bit2X1 multiplexer32bit2X1_mips_m(
rtOut_from_IDEX,
rdOut_from_IDEX,
RegDstOut_from_IDEX,
writeRegOut_from_mips_multiplexer
);
// -------------------------------------------------------
// -------------------------------------------------------
EM_MEM_Register em_mem_register_m (
clock,
hitOut_from_IDEX,
branchTarget_from_alu_mips_m,
zero_from_Execute,
ALUResult_from_Execute,
readData2Out_from_IDEX,
writeRegOut_from_mips_multiplexer,
MemReadOut_from_IDEX,
MemWriteOut_from_IDEX,
BranchOut_from_IDEX,
RegWriteOut_from_IDEX,
MemtoRegOut_from_IDEX,
jump_signal,
branchTargetOut_from_EM_MEM,
zeroFlagOut_from_EM_MEM,
ALUResultOut_from_EM_MEM,
readData2Out_from_EM_MEM,
writeRegOut_from_EM_MEM,
MemReadOut_from_EM_MEM,
MemWriteOut_from_EM_MEM,
BranchOut_from_EM_MEM,
RegWriteOut_from_EM_MEM,
MemToRegOut_from_EM_MEM,
hitOut_from_EM_MEM,
jump_signal_out
);
// -------------------------------------------------------
// -------------------------------------------------------
DataMemory data_memory_m(
clock,
ALUResultOut_from_EM_MEM,
readData2Out_from_EM_MEM,
MemReadOut_from_EM_MEM,
MemWriteOut_from_EM_MEM,
readData_from_DataMemory
);
assign pc_source_from_AND = BranchOut_from_IDEX & zeroFlagOut_from_EM_MEM;
// -------------------------------------------------------
// -------------------------------------------------------
MEM_WB_Register MEM_WB_Register_m(
clock,
hitOut_from_IDEX,
readData_from_DataMemory,
ALUResultOut_from_EM_MEM,
writeRegOut_from_EM_MEM,
RegWriteOut_from_EM_MEM,
MemToRegOut_from_EM_MEM,
hitOut_from_MEM_WB,
readDataOut_from_MEM_WB,
ALUResultOut_from_MEM_WB,
writeRegOut_from_MEM_WB,
RegWriteOut_from_MEM_WB,
MemtoRegOut_from_MEM_WB
);
// -------------------------------------------------------
// -------------------------------------------------------
WriteBack write_back_m(
ALUResultOut_from_MEM_WB,
readDataOut_from_MEM_WB,
MemtoRegOut_from_MEM_WB,
writeDataOut_from_wirte_back
);
endmodule