This repository was archived by the owner on Aug 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathadder.t.v
More file actions
92 lines (89 loc) · 5.08 KB
/
adder.t.v
File metadata and controls
92 lines (89 loc) · 5.08 KB
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
// Adder testbench
`timescale 1 ns / 1 ps
`include "adder.v"
module testFullAdder4bit();
reg [3:0] a;
reg [3:0] b;
wire [3:0] sum;
wire carryout, overflow;
FullAdder4bit adder (sum[3:0], carryout, overflow, a, b);
initial begin
$dumpfile("adder.vcd");
$dumpvars;
$display("Test Case | A | B | Expected Actual | Cout OVF");
$display("Zero Cases");
a= 4'b0001; b=4'b0000; #1000
$display("1+0 (0001+0000)| %b | %b | 0001 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0010; b=4'b0000; #1000
$display("2+0 (0010+0000)| %b | %b | 0010 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0100; b=4'b0000; #1000
$display("4+0 (0100+0000)| %b | %b | 0100 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b1111; b=4'b0000; #1000
$display("-1+0 (1111+0000)| %b | %b | 1111 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b1110; b=4'b0000; #1000
$display("-2+0 (1110+0000)| %b | %b | 1110 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b1100; b=4'b0000; #1000
$display("-4+0 (1100+0000)| %b | %b | 1100 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b1000; b=4'b0000; #1000
$display("-2+0 (1000+0000)| %b | %b | 1000 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0111; b=4'b0000; #1000
$display(" 7+0 (0111+0000)| %b | %b | 0111 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0000; b=4'b0000; #1000
$display(" 0+0 (0000+0000)| %b | %b | 0000 %b | %b %b", a, b, sum, carryout, overflow);
$display("Mirrored Zero Cases");
a= 4'b0000; b=4'b0001; #1000
$display(" 0+1 (0000+0001)| %b | %b | 0001 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0000; b=4'b0010; #1000
$display(" 0+2 (0000+0010)| %b | %b | 0010 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0000; b=4'b0100; #1000
$display(" 0+4 (0000+0100)| %b | %b | 0100 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0000; b=4'b0111; #1000
$display(" 0+7 (0000+0111)| %b | %b | 0111 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0000; b=4'b1111; #1000
$display("0+-1 (0000+1111)| %b | %b | 1111 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0000; b=4'b1110; #1000
$display("0+-2 (0000+1110)| %b | %b | 1110 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0000; b=4'b1100; #1000
$display("0+-4 (0000+1100)| %b | %b | 1100 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0000; b=4'b1000; #1000
$display("0+-8 (0000+1000)| %b | %b | 1000 %b | %b %b", a, b, sum, carryout, overflow);
$display("Testing Internal Carryouts");
a= 4'b0001; b=4'b0001; #1000
$display(" 1+1 (0001+0001)| %b | %b | 0010 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0010; b=4'b0010; #1000
$display(" 2+2 (0010+0010)| %b | %b | 0100 %b | %b %b", a, b, sum, carryout, overflow);
$display("Testing External Carryout");
a= 4'b1111; b=4'b1111; #1000
$display("-1-1 (1111+1111)| %b | %b | 1110 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b1110; b=4'b1110; #1000
$display("-2-2 (1110+1110)| %b | %b | 1100 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b1100; b=4'b1100; #1000
$display("-4-4 (1100+1100)| %b | %b | 1000 %b | %b %b", a, b, sum, carryout, overflow);
$display("Test Overflows");
a= 4'b0100; b=4'b0100; #1000
$display("4+4 (0100+0100)| %b | %b | 1000 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0111; b=4'b0111; #1000
$display("7+7 (0111+0111)| %b | %b | 1110 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b1000; b=4'b1000; #1000
$display("-8-8 (1000+1000)| %b | %b | 0000 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0101; b=4'b0100; #1000
$display(" 5+4 (0101+0100)| %b | %b | 1001 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b1011; b=4'b1100; #1000
$display("-5-4 (1011+1100)| %b | %b | 0111 %b | %b %b", a, b, sum, carryout, overflow);
$display("Regular Cases");
a= 4'b0001; b=4'b0010; #1000
$display("1+2 (0001+0010)| %b | %b | 0011 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0010; b=4'b0011; #1000
$display("2+3 (0010+0011)| %b | %b | 0101 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0011; b=4'b0100; #1000
$display("3+4 (0011+0100)| %b | %b | 0111 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0001; b=4'b1110; #1000
$display("1+-2 (0001+1110)| %b | %b | 1111 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b1110; b=4'b1100; #1000
$display("-2-4 (1110+1100)| %b | %b | 1010 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b0010; b=4'b1100; #1000
$display("2+-4 (0010+1100)| %b | %b | 1110 %b | %b %b", a, b, sum, carryout, overflow);
a= 4'b1011; b=4'b0111; #1000
$display("-5+7 (1011+0111)| %b | %b | 0010 %b | %b %b", a, b, sum, carryout, overflow);
end
endmodule