Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

module rca(

input [3:0] a,

input [3:0] b,

input cin,

output [3:0] sum,

output carry);

wire[2:0] c;

fulladd g1(a[0],b[0],cin,sum[0],c[0]);

fulladd g2(a[1],b[1],c[0],sum[1],c[1]);

fulladd g3(a[2],b[2],c[1],sum[2],c[2]);

fulladd g4(a[3],b[3],c[2],sum[3],carry);

endmodule

module fulladd(a,b,cin,sum,carry);

input a,b,cin;

output sum,carry;

assign sum=a^b^cin;

assign carry=(a&b)|(b&cin)|(a&cin);

endmodule

module rac();

reg [3:0] a,b;

reg cin;

wire [3:0] sum;

wire carry;

rca f(a,b,cin,sum,carry);

initial begin

a=4'b1010; b=4'b1101;cin=0;
#10 a=4'b0001;b=4'b1000;cin=0;

#10 a=4'b0011;b=4'b1100;cin=0;

#10 a=4'b0111;b=4'b1110;cin=0;

#10 a=4'b1111;b=4'b1111;cin=0;

#10 $finish;

end

endmodule

You might also like