-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSC_top_sim.v
266 lines (180 loc) · 4.16 KB
/
SC_top_sim.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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2017/04/13 20:28:17
// Design Name:
// Module Name: SC_top_sim
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module SC_top_sim();
//input
reg clk;
reg reset;
reg MIO_ready;
reg [31:0]inst_in;
reg [31:0]Data_in;
//output
wire mem_w; //memory write enable
wire[31:0]PC_out; //ROM Address
wire[31:0]Addr_out; //RAM Address
wire[31:0]Data_out; //RAM Write Data
reg[5:0] OPCODE;
reg[4:0] RS;
reg[4:0] RT;
reg[4:0] RD;
reg[4:0] SHAMT;
reg[5:0] FUNC;
//assign inst_in = {OPCODE, RS, RT, RD, SHAMT, FUNC};
always #50 clk = ~clk;
initial begin
reset = 1;
clk = 1;
inst_in = 0;
Data_in = 0;
inst_in = 0;
#100; //0-100
reset = 0;
//add
OPCODE = 0;
RS = 17;
RT = 18;
RD = 19;
SHAMT = 0;
FUNC = 6'b100000;
inst_in = {OPCODE, RS, RT, RD, SHAMT, FUNC};
#100;
//add
OPCODE = 0;
RS = 18;
RT = 19;
RD = 19;
SHAMT = 0;
FUNC = 6'b100000;
inst_in = {OPCODE, RS, RT, RD, SHAMT, FUNC};
#100;
//and
OPCODE = 0;
RS = 18;
RT = 19;
RD = 19;
SHAMT = 0;
FUNC = 6'b100100;
inst_in = {OPCODE, RS, RT, RD, SHAMT, FUNC};
#100;
//sub
OPCODE = 0;
RS = 18;
RT = 19;
RD = 19;
SHAMT = 0;
FUNC = 6'b100010;
inst_in = {OPCODE, RS, RT, RD, SHAMT, FUNC};
#100;
//=============== LW =================//
OPCODE = 6'b100011;
RS = 15;
RT = 16;
inst_in = {OPCODE, RS, RT, 16'h0004};
Data_in = 32'hcdcdcdcd;
#100;
// ============= beq =================//
OPCODE = 6'b000100;
RS = 15;
RT = 15;
inst_in = {OPCODE, RS, RT, 16'hFFFC};
Data_in = 32'hcdcdcdcd;
#100;
// ============= Jump ================ //
OPCODE = 6'b000010;
RS = 15;
RT = 15;
inst_in = {OPCODE, 26'h4};
Data_in = 32'hcdcdcdcd;
#100;
// ============= JR ================ //
OPCODE = 6'b000000;
RS = 15;
FUNC = 6'b001000;
inst_in = {OPCODE, RS, 15'b0, FUNC};
#50
OPCODE = 6'b000000;
RS = 16;
FUNC = 6'b001000;
inst_in = {OPCODE, RS, 15'b0, FUNC};
#50
// ============= ADDI ================ //
OPCODE = 6'b001000;
RS = 14;
RT = 14;
inst_in = {OPCODE, RS, RT, 16'h8000};
#100;
// ============= SLTI ================ //
OPCODE = 6'b001010;
RS = 13;
RT = 13;
inst_in = {OPCODE, RS, RT, 16'hd};
#50;
inst_in = {OPCODE, RS, RT, 16'he};
#50;
// ============= ANDI ================ //
OPCODE = 6'b001100;
RS = 12;
RT = 12;
inst_in = {OPCODE, RS, RT, 16'hcdc8};
#100;
// ============= ORI ================ //
OPCODE = 6'b001101;
RS = 11;
RT = 11;
inst_in = {OPCODE, RS, RT, 16'hcdcd};
#100;
// ============= SW ================ //
OPCODE = 6'b101011;
RS = 10;
RT = 10;
inst_in = {OPCODE, RS, RT, 16'h0004};
#100;
// ============= LUI ================ //
OPCODE = 6'b001111;
RT = 9;
inst_in = {OPCODE, 5'b0, RT, 16'hcdcd};
#100;
// ============= Shift right ================ //
OPCODE = 6'b000000;
RT = 9;
RD = 8;
SHAMT = 3;
FUNC = 6'b000010;
inst_in = {OPCODE, 5'b0, RT, RD, SHAMT, FUNC};
#100;
// ============= jal ================ //
OPCODE = 6'b000011;
inst_in = {OPCODE, 26'hf};
#100;
$finish;
end
SCPU_v1 uut2(
.clk(clk),
.reset(reset),
.inst_in(inst_in),
.Data_in(Data_in),
.mem_w(mem_w),
.PC_out(PC_out),
.Addr_out(Addr_out),
.Data_out(Data_out),
.test_reg_index(),
.test_reg_result()
);
endmodule