forked from jmahler/mips-cpu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cla_adder_4bit.v
49 lines (34 loc) · 1.09 KB
/
cla_adder_4bit.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
/*
* cla_adder_4bit.v - 4 bit carry lookahead adder
*/
`include "cla_full_adder.v"
`ifndef _cla_adder_4bit
`define _cla_adder_4bit
module cla_adder_4bit(
input wire [3:0] a,
input wire [3:0] b,
input wire c_in,
output wire [3:0] s,
output wire c_out);
wire [4:0] c;
wire [3:0] g, p;
assign c[0] = c_in;
assign c_out = c[4];
cla_full_adder add0(.a(a[0]), .b(b[0]), .c(c[0]),
.g(g[0]), .p(p[0]), .s(s[0]));
assign c[1] = g[0] | (p[0] & c[0]);
cla_full_adder add1(.a(a[1]), .b(b[1]), .c(c[1]),
.g(g[1]), .p(p[1]), .s(s[1]));
/*assign c[2] = g[1] | (p[1] & c[1]);*/
assign c[2] = g[1] | (p[1] & (g[0] | (p[0] & c[0])));
cla_full_adder add2(.a(a[2]), .b(b[2]), .c(c[2]),
.g(g[2]), .p(p[2]), .s(s[2]));
/*assign c[3] = g[2] | (p[2] & c[2]);*/
assign c[3] = g[2] | (p[2] & (g[1] | (p[1] & (g[0] | (p[0] & c[0])))));
cla_full_adder add3(.a(a[3]), .b(b[3]), .c(c[3]),
.g(g[3]), .p(p[3]), .s(s[3]));
/*assign c[4] = g[3] | (p[3] & c[3]);*/
assign c[4] = g[3] | (p[3] &
(g[2] | (p[2] & (g[1] | (p[1] & (g[0] | (p[0] & c[0])))))));
endmodule
`endif