You are on page 1of 2

module halfad(s,c,a,b);

input a,b;

output s,c;

xor new(s,a,b);

and new1(c,a,b);

endmodule

module fullad(a,b,cin,s,cout);

input a,b,cin;

output s,cout;

wire s1,c1,c2;

halfad h1(s1,c1,a,b);

halfad h2(s,c2,s1,cin);

or new1(cout,c1,c2);

endmodule

module fullad4(s,cout,a,b,cin);

output [3:0]s;

output cout;

input [3:0] a,b;

input cin;

wire c1,c2,c3;

fullad4 new1(s[0],c1,a[0],b[0],cin);

fullad4 new2(s[1],c1,a[1],b[1],c1);

fullad4 new3(s[2],c1,a[2],b[2],c2);

fullad4 new4(s[3],c1,a[3],b[3],c3);
endmodule

module tb_fullad4;

wire [3:0] ts;

wire cout;

reg [3:0] ta,tb;

reg tcin;

fullad4 new(.s(ts),.cout(tcout),.a(ta),.b(tb),.cin(tcin));

initial

begin

ta=4'd2;tb=4'd2;tcin=1'b0;

#5

ta=4'd2;tb=4'd3;tcin=1'b0;

end

initial

begin

//$monitor("$time ta=%d tb=%d tcin=%cin ts=%d tcout=%d", ta,tb,tcin,ts,tcout);

end

endmodule

You might also like