An adder is a digital circuit that performs addition
of numbers. In many computers and other kinds of processors adders are used in
the arithmetic logic units or ALU. They are also used in other parts of the
processor, where they are used to calculate addresses, table indices, increment
and decrement operators and similar operations.
Verilog Code for 1-bit full adder
module
full_adder(sum, cout, in1, in2, cin);
output wire sum;
output wire
cout;
input wire in1,
in2, cin;
wire temp1,
temp2, temp3;
xor(sum,in1,in2,cin);
and(temp1,in1,in2);
and(temp2,in1,cin);
and(temp3,in2,cin);
or(cout,temp1,temp2,temp3);
endmodule
Verilog code for 8-bit
RCA
module ripple_8(sum,cout,in1,in2,cin);
output wire[7:0] sum;
output wire cout;
input wire[7:0] in1,in2;
input wire cin;
wire c1,c2,c3,c4,c5,c6,c7;
full_adder FA1(sum[0],c1,in1[0],in2[0],cin);
full_adder FA2(sum[1],c2,in1[1],in2[1],c1);
full_adder FA3(sum[2],c3,in1[2],in2[2],c2);
full_adder FA4(sum[3],c4,in1[3],in2[3],c3);
full_adder FA5(sum[4],c5,in1[4],in2[4],c4);
full_adder FA6(sum[5],c6,in1[5],in2[5],c5);
full_adder FA7(sum[6],c7,in1[6],in2[6],c6);
full_adder FA8(sum[7],cout,in1[7],in2[7],c7);
endmodule
Test Bench for 8-bit ripple carry adder
module rca_tb;
// Inputs
reg [7:0] in1;
reg [7:0] in2;
reg cin;
// Outputs
wire [7:0] sum;
wire cout;
// Instantiate the Unit Under Test (UUT)
ripple_8 uut (
.sum(sum),
.cout(cout),
.in1(in1),
.in2(in2),
.cin(cin)
);
initial begin
// Initialize Inputs
in1 = 01111011;
in2 = 01111000;
cin = 0;
#10
in1 = 11111011;
in2 = 11111000;
cin = 0;
#10
in1 = 01000011;
in2 = 01101100;
cin = 0;
#10
in1 = 11000011;
in2 = 01111111;
cin = 0;
// Wait 10 ns for global reset to finish
#10;
end
endmodule
Note: Execute all the codes at the same time
No comments:
Post a Comment