You are on page 1of 5

Coding:

module carrylookahead(sum,cout,a,b,cin);
input [3:0]a,b;
input cin;
output [3:0]sum;
output cout;
wire
p0,p1,p2,p3,g0,g1,g2,g3,c1,c2,c3,w1,w2,w3,w4,w5,w6,w7,w8,w9,w10,w11,w12,w13
,w14;
and(g0,a[0],b[0]);
and(g1,a[1],b[1]);
and(g2,a[2],b[2]);
and(g3,a[3],b[3]);

xor(w1,a[0],b[0]);
and(p0,w1,cin);
xor(w2,a[1],b[1]);
and(p1,w2,c1);
xor(w3,a[2],b[2]);
and(p2,w3,c2);
xor(w4,a[3],b[3]);
and(p3,w4,c3);

and(w5,p0,cin);
or(c1,g0,w5);

and(w6,p1,g0);
and(w7,p1,p0,cin);
or(c2,g1,w6,w7);
and(w8,p2,g1);
and(w9,p1,p2,g0);
and(w10,p0,p1,p2,cin);
or(c3,g2,w8,w9,w10);

and(w11,p3,g3);
and(w12,p2,p3,g1);
and(w13,p1,p2,p3,g0);
and(w14,p0,p1,p2,p3,cin);
or(cout,g3,w11,w12,w13,w14);

xor(sum[0],a[0],b[0],cin);
xor(sum[1],a[1],b[1],c1);
xor(sum[2],a[2],b[2],c2);
xor(sum[3],a[3],b[3],c3);
endmodule

initial begin
a = 4'b0000;
b =4'b0000;
cin = 0;
#100;
a = 4'b0001;
b =4'b0001;
cin = 0;
#100;a = 4'b0010;
b =4'b0010;
cin = 0;
#100;
a = 4'b0001;
b =4'b0010;
cin = 0;
#100;
a = 4'b1111;
b =4'b1111;
cin = 0;
#100;

end

endmodule
Waveform: