-
Notifications
You must be signed in to change notification settings - Fork 0
/
carry look ahead adder.v
39 lines (30 loc) · 996 Bytes
/
carry look ahead adder.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
module four_bit_carryLookAhead_adder(s, cout, a, b, cin);
input [3:0] a, b;
input cin;
output [3:0] s;
output cout;
wire [3:0] p, g, c;
assign g = a&b;
assign p = a^b;
assign c[0] = cin;
assign c[1] = g[0] | (p[0]&c[0]);
assign c[2] = g[1] | (p[1]&c[1]);
assign c[3] = g[2] | (p[2]&c[2]);
assign cout = g[3] | (p[3]&c[3]);
assign s = p^c;
endmodule
// module carry_look_ahead_adder(s, cout, a, b, cin);
// input [3:0] a, b;
// input cin;
// output [3:0] s;
// output cout;
// wire [3:0] p, g, c;
// assign p = a ^ b;
// assign g = a & b;
// assign c[0] = cin;
// assign c[1] = g[0] | (p[0] & c[0]);
// assign c[2] = g[1] | (p[1] & g[0]) | (p[1] & p[0] & c[0]);
// assign c[3] = g[2] | (p[2] & g[1]) | (p[2] & p[1] & g[0]) | (p[2] & p[1] & p[0] & c[0]);
// assign cout = g[3] | (p[3] & g[2]) | (p[3] & p[2] & g[1]) | (p[3] & p[2] & p[1] & g[0]) | (p[3] & p[2] & p[1] & p[0] & c[0]);
// assign s = p ^ c;
// endmodule