-
Notifications
You must be signed in to change notification settings - Fork 0
/
and_tb.v
60 lines (50 loc) · 1.26 KB
/
and_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
module tb_and();
reg [7:0] A, B;
wire [7:0] Y;
reg [3:0] error_cnt;
task check;
input [7:0] expected;
begin
if (Y != expected)
begin
$display("ERROR: A=%b B=%b != Y=%b (gives Y=%b)", A, B, expected, Y);
error_cnt++;
end
else
begin
$display("PASS");
end
end
endtask
and_func u_and8bit(
.A(A),
.B(B),
.Y(Y)
);
// Clock not needed for combinational logic like AND
// Apply test vectors
initial begin
error_cnt = 0;
$dumpfile("and_func.vcd");
$dumpvars(0, tb_and);
// Test 1: A=0x00, B=0x00
A = 8'b00000000; B = 8'b00000000;
#10
check(8'b00000000);
// Test 2: A=0xFF, B=0x00
A = 8'b11111111; B = 8'b00000000;
#10
check(8'b00000000);
// Test 3: A=0xFF, B=0xFF
A = 8'b11111111; B = 8'b11111111;
#10
check(8'b11111111);
// Test 4: A=0x55, B=0xAA
A = 8'b01010101; B = 8'b10101010;
#10
check(8'b00000000);
$display("error_cnt=%b", error_cnt);
// End of tests
$finish;
end
endmodule