-
Notifications
You must be signed in to change notification settings - Fork 0
/
muu_tb.v
204 lines (143 loc) · 3.65 KB
/
muu_tb.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
`timescale 1ns / 1ps
module muu_tb;
// Inputs
reg clk;
reg [31:0] rs, rt;
reg [3:0] operation;
wire [31:0] result;
wire div_zero;
muu test_unit(
.clk(clk),
.rs(rs),
.rt(rt),
.operation(operation),
.out(result),
.div_zero(div_zero)
);
task test_result;
input [31:0] expected_value;
begin
if (result == expected_value)
$display("correct\n");
else begin
$display("INCORRECT");
$display("Expected: %h; Output: %h\n", expected_value, result);
end
end
endtask
always begin
clk = 1'b1;
#250; // high for 20
clk = 1'b0;
#250; // low for 20
end
initial begin
/* ---------- MUL ---------- */
rs = 32'd7;
rt = 32'd2;
operation = 4'b0000; // MUL
#250; // LOW
$display("%0h * %0h = %0h", rs, rt, result);
$display("div_zero = %0b", div_zero);
test_result(32'd14);
#250; // HIGH
/* ---------- MUL ---------- */
rs = 32'd7;
rt = 32'hffff_fffe;
operation = 4'b0000; // MUL
#250; // LOW
$display("%0h * %0h = %0h", rs, rt, result);
$display("div_zero = %0b", div_zero);
test_result(32'hffff_fff2);
#250; // HIGH
/* ---------- MULT ---------- */
rs = 32'h704D_0054;
rt = 32'h400B_000C;
operation = 4'b0001; // MULT
#250; // LOW
$display("%0h * %0h = %0h; deve manter valor anterior", rs, rt, result);
$display("div_zero = %0b", div_zero);
test_result(32'hffff_fff2);
#250; //HIGH
/* ---------- MFHI ---------- */
operation = 4'b0101; //MFHI
#250; // LOW
$display("HI = %0h", result);
test_result(32'h1C18_1369);
#250; //HIGH
/* ---------- MFLO ---------- */
operation = 4'b0110; //MFLO
#250; // LOW
$display("LO = %0h", result);
test_result(32'h4738_03F0);
#250; //HIGH
/* ---------- MADD ---------- */
// Usando os mesmos rs, rt do ultimo teste
operation = 4'b0010; // MADD
#250; // LOW
$display("Resultados do MADD:");
$display("%0h * %0h = %0h; deve manter valor anterior", rs, rt, result);
$display("div_zero = %0b", div_zero);
test_result(32'h4738_03F0);
#250; //HIGH
operation = 4'b0101; //MFHI
#250; // LOW
$display("HI = %0h", result);
test_result(32'h3830_26D2);
#250; //HIGH
operation = 4'b0110; //MFLO
#250; // LOW
$display("LO = %0h", result);
test_result(32'h8E70_07E0);
#250; //HIGH
/* Zeramento dos registradores HI/LO p/ teste com SUBU */
rs = 32'h0;
rt = 32'h0;
operation = 4'b0001; // MULT
#250; // LOW
#250; //HIGH
/* ---------- MSUBU ---------- */
rs = 32'hFFFF_FFFF; // Unsigned operation
rt = 32'h2;
operation = 4'b0011; // MSUBU
#250; // LOW
#250; //HIGH
operation = 4'b0101; //MFHI
#250; // LOW
$display("Resultados do MSUBU:");
$display("HI = %0h", result);
test_result(32'hFFFF_FFFF);
#250; //HIGH
operation = 4'b0110; //MFLO
#250; // LOW
$display("LO = %0h", result);
test_result(32'h2);
#250; //HIGH
/* ---------- DIV ---------- */
rs = 32'h21;
rt = 32'h10;
operation = 4'b0100; // DIV
#250; // LOW
#250; //HIGH
operation = 4'b0101; //MFHI
#250; // LOW
$display("%0h mod %0h = %0h", rs, rt, result);
$display("HI = %0h", result);
test_result(32'h1);
#250; //HIGH
operation = 4'b0110; //MFLO
#250; // LOW
$display("%0h / %0h = %0h", rs, rt, result);
$display("LO = %0h", result);
$display("div_zero = %0b", div_zero);
test_result(32'h2);
#250; //HIGH
/* ---------- DIV by zero ---------- */
rt = 32'h0;
operation = 4'b0100; // DIV
#250; // LOW
$display("%0h / %0h = %0h; mantem valor anterior", rs, rt, result);
$display("div_zero = %0b", div_zero);
$stop;
end
endmodule