forked from Jec222/EE4352_Lab6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ha_tb2.v
65 lines (60 loc) · 988 Bytes
/
ha_tb2.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
`include "HA.v"
module ha_tb;
reg A,B;
`ifdef T2
reg clk;
`endif
wire Cout,Sum;
HA HA1(A,B,Cout,Sum);
initial
begin
$dumpfile("ha.vcd");
$dumpvars(0,HA1);
end
`ifdef T1
initial
begin
#10 A=0; B=0;
#10 $display($time, " %b+%b=%b%b",A,B,Cout,Sum);
if (Sum==0 && Cout==0);
else $display("failed");
A=0; B=1;
#10 $display($time, " %b+%b=%b%b",A,B,Cout,Sum);
if (Sum==1 && Cout==0);
else $display("failed");
A=1; B=0;
#10$display($time, " %b+%b=%b%b",A,B,Cout,Sum);
if (Sum==1 && Cout==0);
else $display("failed");
A=1; B=1;
#10 $display($time, " %b+%b=%b%b",A,B,Cout,Sum);
if (Sum==0 && Cout==1);
else $display("failed. Expected '10' and got %b%b",Cout,Sum );
#10 $finish;
end
`elsif T2
initial
begin
A=0;
B=0;
clk=0;
forever #10 clk=~clk;
end
initial
begin
repeat(10)@(posedge clk)
begin
A=$random;
B=$random;
end
#200 $finish;
end
initial
begin
$monitor("%b+%b = %b%b", A,B,Cout,Sum);
end
`else
initial
$display("NO COMPILER DIRECTIVE");
`endif
endmodule