0% found this document useful (0 votes)
30 views

Carry Save Adder: Fulladder

The document describes a carry save adder (CSA) module and test bench module. The CSA module takes in 4-bit inputs x, y, z and outputs a 5-bit sum s and carry cout by using four fulladder modules. The test bench module exhaustively tests all input combinations of x, y, z against the expected output sum and carry to check for errors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Carry Save Adder: Fulladder

The document describes a carry save adder (CSA) module and test bench module. The CSA module takes in 4-bit inputs x, y, z and outputs a 5-bit sum s and carry cout by using four fulladder modules. The test bench module exhaustively tests all input combinations of x, y, z against the expected output sum and carry to check for errors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

fulladder

module fulladder
( input a,b,cin,
output sum,carry
);

always_comb

begin

sum = a ^ b ^ cin;
carry = (a & b) | (cin & b) | (a & cin);

end

endmodule

CARRY SAVE ADDER

module CSA
( input [3:0] x,y,z,
output [4:0] s,
output cout
);

wire [3:0] c1,s1,c2;

fulladder fa_inst10(x[0],y[0],z[0],s1[0],c1[0]);
fulladder fa_inst11(x[1],y[1],z[1],s1[1],c1[1]);
fulladder fa_inst12(x[2],y[2],z[2],s1[2],c1[2]);
fulladder fa_inst13(x[3],y[3],z[3],s1[3],c1[3]);

fulladder fa_inst20(s1[1],c1[0],1'b0,s[1],c2[1]);
fulladder fa_inst21(s1[2],c1[1],c2[1],s[2],c2[2]);
fulladder fa_inst22(s1[3],c1[2],c2[2],s[3],c2[3]);
fulladder fa_inst23(1'b0,c1[3],c2[3],s[4],cout);

assign s[0] = s1[0];

endmodule
TEST BENCH CSA

module tb_adder;

reg [3:0] x,y,z;


wire [4:0] s;
wire cout;
integer i,j,k,error;

// Instantiate the Unit Under Test (UUT)


CSA uut (x,y,z,s,cout);

//Stimulus block - all the input combinations are tested here.


//the number of errors are recorded in the signal named "error".
initial begin
// Initialize Inputs
x = 0;
y = 0;
z = 0;
error = 0;
//three for loops to test all input combinations.
for(i=0;i<16;i=i+1) begin
for(j=0;j<16;j=j+1) begin
for(k=0;k<16;k=k+1) begin
x = i;
y = j;
z = k;
#10;
if({cout,s} != (i+j+k))
error <= error + 1;
end
end
end
end

endmodule

You might also like