-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu_tb.sv
188 lines (165 loc) · 4.55 KB
/
cpu_tb.sv
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
module cpu_tb ();
reg SIM_clk, SIM_reset, SIM_s, SIM_load;
reg [15:0] SIM_in;
wire [15:0] SIM_out;
wire SIM_N, SIM_V, SIM_Z, SIM_w;
reg err;
//cpu module instantiation
cpu DUT(SIM_clk, SIM_reset, SIM_s, SIM_load, SIM_in, SIM_out, SIM_N, SIM_V, SIM_Z, SIM_w);
//clk cycle
initial begin
SIM_clk = 0; #5;
forever begin
SIM_clk = 1; #5;
SIM_clk = 0; #5;
end
end
//Test benches
initial begin
//Initializations
err = 0;
SIM_reset = 1; SIM_s = 0; SIM_load = 0; SIM_in = 16'b0;
#10;
SIM_reset = 0;
#10;
//Test: MOV R1, #70
SIM_in = 16'b1101000101000110;
SIM_load = 1;
#10;
SIM_load = 0;
SIM_s = 1;
#10
SIM_s = 0;
@(posedge SIM_w); // wait for w to go high again
#10;
if (cpu_tb.DUT.DP.REGFILE.R1 !== 16'b1101000101000110) begin
err = 1;
$display("FAILED TEST #1: MOV R1, #70");
$stop;
end
//Test: MOV R2, #2
@(negedge SIM_clk);
SIM_in = 16'b1101001000000010;
SIM_load = 1;
#10;
SIM_load = 0;
SIM_s = 1;
#10
SIM_s = 0;
@(posedge SIM_w); // wait for w to go high again
#10;
if (cpu_tb.DUT.DP.REGFILE.R2 !== 16'd2) begin
err = 1;
$display("FAILED TEST #2: MOV R2, #2");
$stop;
end
//Test: MOV R3, #8
@(negedge SIM_clk);
SIM_in = 16'b1101001100001000;
SIM_load = 1;
#10;
SIM_load = 0;
SIM_s = 1;
#10
SIM_s = 0;
@(posedge SIM_w); // wait for w to go high again
#10;
if (cpu_tb.DUT.DP.REGFILE.R3 !== 16'd8) begin
err = 1;
$display("FAILED TEST #3: MOV R3, #8");
$stop;
end
//Test: MOV R1, R0, LSL#1 (R1 Should Equal 20)
@(negedge SIM_clk);
SIM_in = 16'b1100000000101000;
SIM_load = 1;
#10;
SIM_load = 0;
SIM_s = 1;
#10
SIM_s = 0;
@(posedge SIM_w); // wait for w to go high again
#10;
if (cpu_tb.DUT.DP.REGFILE.R1 !== 16'd20) begin
err = 1;
$display("FAILED TEST #9: MOV R1, R0, LSL#1");
$stop;
end
//Test: ADD R2, R1, R5 (R2 Should Equal 24)
@(negedge SIM_clk);
SIM_in = 16'b1010000101000101;
SIM_load = 1;
#10;
SIM_load = 0;
SIM_s = 1;
#10
SIM_s = 0;
@(posedge SIM_w); // wait for w to go high again
#10;
if (cpu_tb.DUT.DP.REGFILE.R2 !== 16'd24) begin
err = 1;
$display("FAILED TEST #11: ADD R2, R1, R5");
$stop;
end
//Test: CMP R0, R1, LSR#1 (R0 Should Equal R1/2)
@(negedge SIM_clk);
SIM_in = 16'b1010100000010001;
SIM_load = 1;
#10;
SIM_load = 0;
SIM_s = 1;
#10
SIM_s = 0;
@(posedge SIM_w); // wait for w to go high again
#10;
if (cpu_tb.DUT.Z !== 1'd1) begin
err = 1;
$display("FAILED TEST #14: CMP R0, R1, LSR#1");
$stop;
end
//Test: AND R7, R2, R3
@(negedge SIM_clk);
SIM_in = 16'b1011001011100011;
SIM_load = 1;
#10;
SIM_load = 0;
SIM_s = 1;
#10
SIM_s = 0;
@(posedge SIM_w); // wait for w to go high again
#10;
if (cpu_tb.DUT.DP.REGFILE.R7 !== 16'b1111111111110110) begin
err = 1;
$display("FAILED TEST #19: AND R7, R2, R3");
$stop;
end
//Test: MVN R4, R4
@(negedge SIM_clk);
SIM_in = 16'b1011100010000100;
SIM_load = 1;
#10;
SIM_load = 0;
SIM_s = 1;
#10
SIM_s = 0;
@(posedge SIM_w); // wait for w to go high again
#10;
if (cpu_tb.DUT.DP.REGFILE.R4 !== 16'b1111111111101010) begin
err = 1;
$display("FAILED TEST #22a: MVN R4, R4");
$stop;
end
if (cpu_tb.DUT.N !== 1'd1) begin
err = 1;
$display("FAILED TEST #22b: MVN R4, R4");
$stop;
end
if (cpu_tb.DUT.V !== 1'd1) begin
err = 1;
$display("FAILED TEST #22c: MVN R4, R4");
$stop;
end
if (~err) $display("All tests passed");
$stop;
end
endmodule