Full adder
module fulladder(a,b,cin,s,cout);
input a, b, cin;
output s, cout;
wire x,y,z;
xor g1(x,a,b);
and g2(y,a,b);
and g3(z, x,cin);
xor g4(s, x,cin);
or g5(cout, y, z);
endmodule
4-bit Ripple carry adder using Full adder
module ripplecarryadder(a,b,c,sum,cout);
input [3:0]a,b;
input cin;
output reg [3:0]sum;
output cout;
wire [2:0]c;
fulladder f1(a[0],b[0],cin,sum[0],c[0]);
fulladder f2(a[1],b[1],c[0],sum[1],c[1]);
fulladder f3(a[2],b[2],c[1],sum[2],c[2]);
fulladder f4(a[3],b[3],c[2],sum[3],cout);
endmodule
No comments:
Post a Comment