-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfull_adder.v
More file actions
106 lines (68 loc) · 1.24 KB
/
full_adder.v
File metadata and controls
106 lines (68 loc) · 1.24 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
module full_adder(s, c, x, y, z);
input x, y, z;
output s, c;
/* Gate Level Modelling */
wire w1, w2, w3;
xor x1(s, x, y, z);
and a1(w1, x, y);
and a2(w2, y, z);
and a3(w3, z, x);
or o1(c, w1, w2, w3);
/* Structural Model using half adders
wire s1, c1, c2;
half_adder ha1(s1, c1, x, y);
half_adder ha2(s, c2, s1, z);
or(c, c1, c2);
*/
/* Dataflow Model
assign s = x^y^z;
assign c = x&y + y&z + z&x;
*/
/* Behavioural Model (use reg in output) In case, use either {x, y, z} (preferable) or x|y|z
reg s, c;
always @(x or y or z) begin
case(x|y|z)
3'b000: begin
s = 0; c = 0;
end
3'b001: begin
s = 1; c = 0;
end
3'b010: begin
s = 1; c = 0;
end
3'b011: begin
s = 0; c = 1;
end
3'b100: begin
s = 1; c = 0;
end
3'b101: begin
s = 0; c = 1;
end
3'b110: begin
s = 0; c = 1;
end
3'b111: begin
s = 1; c = 1;
end
endcase
end
*/
/*
module testbench;
reg x, y, z;
wire s, c;
full_adder fa(s, c, x, y, z);
initial begin
x = 0; y = 0; z = 0;
#100 x = 0; y = 0; z = 1;
#100 x = 0; y = 1; z = 0;
#100 x = 0; y = 1; z = 1;
#100 x = 1; y = 0; z = 0;
#100 x = 1; y = 0; z = 1;
#100 x = 1; y = 1; z = 0;
#100 x = 1; y = 1; z = 1;
end
*/
endmodule