-
Notifications
You must be signed in to change notification settings - Fork 2
/
Register_Test.v
344 lines (292 loc) · 7.66 KB
/
Register_Test.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
`include "parameters.vh"
module Register_Test();
//This is the clock
reg clk;
//this is the input to select one of the 16 registers
reg [3:0] reg_read_a;
reg [3:0] reg_read_b;
//This is the register that the ALU will write to if write_enable 1
reg [3:0] reg_write;
reg write_enable;
reg reset;
//This is the input to the ALU
//ALU STUFF
reg [15:0] opcode;
reg carry_in;
wire [15:0] c;
//Output registers from Register, input to ALU
wire [15:0] reg_a;
wire [15:0] reg_b;
reg [4:0] flags;
//initialize initial register counter to 0
Register_File reg_file (
.reg_write(reg_write),
.reg_read_a(reg_read_a),
.reg_read_b(reg_read_b),
.write_enable(write_enable),
.reset(reset),
.alu_input(c),
.reg_a(reg_a),
.reg_b(reg_b),
.clk(clk)
);
ALU alu (
.a(reg_a),
.b(reg_b),
.opcode(opcode),
.carry_in(carry_in), //haven't implemented in ALU_FSM
.c(c),
.flags(flags)
);
always #4 clk = !clk;
initial begin
flags=5'b0;
clk=1;
reset = 1'b1;
//changing this to from 0 to high impedence
write_enable = 1'b0;
carry_in = 1'b0;
reg_read_a = 4'd0;
reg_read_b = 4'd0;
//changing this to from 0 to high impedence
reg_write = 4'd0;
opcode = 15'b0;//{`ADDI, 4'b0000, 8'b00000001};
#99
//put 1 in the original register 1
reset = 1'b0;
reg_read_a = 4'd8;
reg_read_b = 4'd1;
reg_write = 4'd0;
opcode = {`ADDI, 4'b0000, 8'b00000001};
write_enable = 1;
#8
if((c == 16'b1))
begin
$display("Correct: %b %b %b %d", reg_a, reg_b, c, c);
end
else
begin
$display("ERROR: %b %b %b %d", reg_a, reg_b, c, c);
end
#8
//Do the same for register 2
reset = 1'b0;
//SHOULD CHANGE TO OTHER ZERO REGISTER
reg_read_a = 4'd0;
reg_read_b = 4'd1;
reg_write = 4'd1;
write_enable = 1;
opcode = {`ADDI, 4'b0000, 8'b00000001};
if((c == 1))
begin
$display("Correct: %b %b %b %d", reg_a, reg_b, c, c);
end
else $display("ERROR: %b %b %b %d", reg_a, reg_b, c, c);
#8
reset = 1'b0;
reg_read_a = 4'd0;
reg_read_b = 4'd1;
reg_write = 4'd2;
write_enable = 1;
opcode = {`RTYPE, 4'b0000, `EXT_ADD, 4'b0000};
if((c == 2))
begin
$display("Correct: %b %b %b %d", reg_a, reg_b, c, c);
end
else $display("ERROR: %b %b %b %d", reg_a, reg_b, c, c);;
#8
reset = 1'b0;
//Now we want to add Registers 1 and registers 2
reg_read_a = 4'd1;
reg_read_b = 4'd2;
//We want to add these two together
opcode = {`RTYPE, 4'b0000, `EXT_ADD, 4'b0000};
//this should be 3
write_enable=1'b1;
reg_write = 4'd3;
if((c == 3))
begin
$display("Correct: %b %b %b %d", reg_a, reg_b, c, c);
end
else $display("ERROR: %b %b %b %d", reg_a, reg_b, c, c);
#8
//Now we want to add Registers 2 and registers 3
reset = 1'b0;
reg_read_a = 4'd2; //this is 2
reg_read_b = 4'd3; //this is 3
//We want to add these two together
opcode = {`RTYPE, 4'b0000, `EXT_ADD, 4'b0000};
//this should be 5
write_enable=1'b1;
reg_write = 4'd4;
if((c == 5))
begin
$display("Correct: %b %b %b %d", reg_a, reg_b, c, c);
end
else $display("ERROR: %b %b %b %d", reg_a, reg_b, c, c);
#8
reset = 1'b0;
//Now we want to add Registers 3 and registers 4
reg_read_a = 4'd3; //this is 3
reg_read_b = 4'd4; //this is 4
write_enable=1'b1;
reg_write = 4'd5;
//We want to add these two together
opcode = {`RTYPE, 4'b0000, `EXT_ADD, 4'b0000};
//this should be 8
if((c == 8))
begin
$display("Correct: %b %b %b %d", reg_a, reg_b, c, c);
end
else $display("ERROR: %b %b %b %d", reg_a, reg_b, c, c);
#8
//Now we want to add Registers 4 and registers 5
reset = 1'b0;
reg_read_a = 4'd4; //this is 4
reg_read_b = 4'd5; //this is 5
write_enable=1'b1;
reg_write = 4'd6;
//We want to add these two together
opcode = {`RTYPE, 4'b0000, `EXT_ADD, 4'b0000};
//this should be 13
if((c == 13))
begin
$display("Correct: %b %b %b %d", reg_a, reg_b, c, c);
end
else $display("ERROR: %b %b %b %d", reg_a, reg_b, c, c);
#8
//Now we want to add Registers 5 and registers 6
reset = 1'b0;
reg_read_a = 4'd5; //this is 5
reg_read_b = 4'd6; //this is 6
//We want to add these two together
opcode = {`RTYPE, 4'b0000, `EXT_ADD, 4'b0000};
//this should be 21
write_enable=1'b1;
reg_write = 4'd7;
if((c == 21))
begin
$display("Correct: %b %b %b %d", reg_a, reg_b, c, c);
end
else $display("ERROR: %b %b %b %d", reg_a, reg_b, c, c);
#8
//Now we want to add Registers 6 and registers 7
reg_read_a = 4'd6; //this is 6
reg_read_b = 4'd7; //this is 7
//We want to add these two together
opcode = {`RTYPE, 4'b0000, `EXT_ADD, 4'b0000};
//this should be 34
write_enable=1'b1;
reg_write = 4'd8;
if((c == 34))
begin
$display("Correct: %b %b %b %d", reg_a, reg_b, c, c);
end
else $display("ERROR: %b %b %b %d", reg_a, reg_b, c, c);
#8
//Now we want to add Registers 2 and registers 3
reg_read_a = 4'd7; //this is 7
reg_read_b = 4'd8; //this is 8
//We want to add these two together
opcode = {`RTYPE, 4'b0000, `EXT_ADD, 4'b0000};
//this should be 55
write_enable=1'b1;
reg_write = 4'd9;
//this writes to Reg 9, but then the problems start
if((c == 55))
begin
$display("Correct: %b %b %b %d", reg_a, reg_b, c, c);
end
else $display("ERROR: %b %b %b %d", reg_a, reg_b, c, c);
#8
reset=0;
//Now we want to add Registers 2 and registers 3
reg_read_a = 4'd8; //this is 8
reg_read_b = 4'd9; //this is 9
//We want to add these two together
opcode ={`RTYPE, 4'b0000, `EXT_ADD, 4'b0000};
//this should be 89
write_enable=1'b1;
reg_write = 4'd10;
if((c == 89))
begin
$display("Correct: %b %b %b %d", reg_a, reg_b, c, c);
end
else $display("ERROR: %b %b %b %d", reg_a, reg_b, c, c);
#8
//Now we want to add Registers 2 and registers 3
reset=0;
reg_read_a = 4'd9; //this is 9
reg_read_b = 4'd10; //this is 10
//We want to add these two together
opcode ={`RTYPE, 4'b0000, `EXT_ADD, 4'b0000};
//this should be 144
write_enable=1'b1;
reg_write = 4'd11;
if((c == 144))
begin
$display("Correct: %b %b %b %d", reg_a, reg_b, c, c);
end
else $display("ERROR: %b %b %b %d", reg_a, reg_b, c, c);
#8
//Now we want to add Registers 2 and registers 3
reg_read_a = 4'd10; //this is 10
reg_read_b = 4'd11; //this is 11
//We want to add these two together
opcode ={`RTYPE, 4'b0000, `EXT_ADD, 4'b0000};
//this should be 233
write_enable=1'b1;
reg_write = 4'd12;//this is 12
if((c == 233))
begin
$display("Correct: %b %b %b %d", reg_a, reg_b, c, c);
end
else $display("ERROR: %b %b %b %d", reg_a, reg_b, c, c);
#8
//Now we want to add Registers 2 and registers 3
reg_read_a = 4'd11; //this is 11
reg_read_b = 4'd12; //this is 12
//We want to add these two together
opcode = {`RTYPE, 4'b0000, `EXT_ADD, 4'b0000};
//this should be 377
write_enable=1'b1;
reg_write = 4'd13;//this is 13
if((c == 377))
begin
$display("Correct: %b %b %b %d", reg_a, reg_b, c, c);
end
else $display("ERROR: %b %b %b %d", reg_a, reg_b, c, c);
#8
//Now we want to add Registers 2 and registers 3
reg_read_a = 4'b1100; //this is 12
reg_read_b = 4'b1101; //this is 13
//We want to add these two together
opcode = {`RTYPE, 4'b0000, `EXT_ADD, 4'b0000};
//this should be 610
write_enable=1'b1;
reg_write = 4'b1110;
if((c == 610))
begin
$display("Correct: %b %b %b %d", reg_a, reg_b, c, c);
end
else $display("ERROR: %b %b %b %d", reg_a, reg_b, c, c);
#8
//Now we want to add Registers 2 and registers 3
reg_read_a = 4'b1101; //this is 12
reg_read_b = 4'b1110; //this is 13
//We want to add these two together
opcode = {`RTYPE, 4'b0000, `EXT_ADD, 4'b0000};
//this should be 610
write_enable=1'b1;
reg_write = 4'b1111;
if((c == 987))
begin
$display("Correct: %b %b %b %d", reg_a, reg_b, c, c);
end
else $display("ERROR: %b %b %b %d", reg_a, reg_b, c, c);
end
//initial
//begin
//
//end
endmodule