You are on page 1of 2

FULLADDER.

V
module fulladd(a,b,cin,sum,cout);
input a,b,cin;
output sum,cout;
reg sum,cout;
always@(a,b,cin)
begin
sum=a^b^cin;
cout=(a&b)|(b&cin)|(cin&a);
end
endmodule
--SERIALADDER.V
module serialadd(asa,bsa,sumsa,coutsa);
input [3:0] asa,bsa;
inout [3:0] sumsa;
inout coutsa;
reg [3:0] sumsa;
reg coutsa;
wire [2:0] c;
fulladd fa0(.a(asa[0]),.b(bsa[0]),.cin(1'b0),.sum(sumsa[0]),.cout(c[0]));
fulladd fa1(.a(asa[1]),.b(bsa[1]),.cin(c[0]),.sum(sumsa[1]),.cout(c[1]));
fulladd fa2(.a(asa[2]),.b(bsa[2]),.cin(c[1]),.sum(sumsa[2]),.cout(c[2]));
fulladd fa3(.a(asa[3]),.b(bsa[3]),.cin(c[2]),.sum(sumsa[3]),.cout(coutsa));
endmodule
--SERIALADDER_TB.V
module saddtest;
reg [3:0] at,bt;
wire [3:0] sumt;
wire coutt;
serialadd sa_t(.asa(at),.bsa(bt),sumsa(sumt),coutsa(coutt));
initial
begin
$display($time,"\t Simulation Starts");
at=4'b1000; bt=4'b1001;
#10 at=4'b1110; bt=4'b1010;
#5 $display("\n");
end
initial
#30 $finish;
initial
$monitor($time,"at=%b,bt=%b,sumt=%b,coutt=%b",at,bt,sumt,coutt);
endmodule
-PARALLELADDER.V
module pad(x,y,z,cin,cout);
input [3:0] x,y;
input cin;
inout [3:0] z;
inout cout;
wire p3,g3,p2,g2,p1,g1,p0,g0,m1,m2,m3,m4,m6,m7,m8,m10,m11,m13,c3,c2,c1;
//Stage1
xor xor1(p3,x[3],y[3]);
and a1(g3,x[3],y[3]);
xor xor2(p2,x[2],y[2]);
and a2(g2,x[2],y[2]);
xor xor3(p1,x[1],y[1]);
and a3(g1,x[1],y[1]);

xor xor4(p0,x[0],y[0]);
and a4(g0,x[0],y[0]);
//Stage2
and a5(m1,cin,p3,p2,p1,p0);
and a6(m2,p3,p2,p1,g0);
and a7(m3,p3,p2,g1);
and a8(m4,p3,g2);
and a9(m6,p0,p1,p2,cin);
and a10(m7,p0,p1,p2);
and a11(m8,p2,g1);
and a12(m10,p1,p0,cin);
and a13(m11,p1,g0);
and a14(m13,p0,cin);
//Stage3
or or1(cout,m1,m2,m3,m4,g3);
or or2(c3,m6,m7,m8,g2);
or or3(c2,m10,m11,g1);
or or4(c1,m13,g0);
//Stage4
xor xor5(z[3],c3,x[3],y[3]);
xor xor6(z[2],c2,x[2],y[2]);
xor xor7(z[1],c1,x[1],y[1]);
xor xor8(z[0],cin,x[0],y[0]);
endmodule
-PARALLELADDER_TB.V
module paddtest;
reg [3:0] at,bt;
reg cint;
wire [3:0] sumt;
wire coutt;
pad sa_t(.x(at),.y(bt),.cin(cint),.z(sumt),.cout(coutt));
initial
begin
$display($time,"\t Simulation Starts");
at=4'b1000; bt=4'b1001;cint=1'b0;
#10 at=4'b1110; bt=4'b1010;
#5 $display("\n");
end
initial
#30 $finish;
initial
$monitor($time,"at=%b,bt=%b,cint=%b,sumt=%b,coutt=%b",at,bt,cint,sumt,coutt);
endmodule