Objective:- To Design and Simulate 4 Bit Ripple Carry Adder, 4 Bit Ripple Borrow Subtractor.
Software / Tool Used:- AMD Vivado
Theory :
1) 4bit Rippe carry Adder
A 4-bit ripple carry adder is a digital circuit that adds two 4-bit binary numbers using full adders connected in
series.
Each full adder adds corresponding bits along with the carry from the previous stage.
The carry “ripples” through each stage, from the least significant bit to the most significant bit.
This simple design is easy to implement but is slower due to carry propagation delay.
2) 4bit Rippe carry subtractor
A 4-bit ripple carry subtractor is used to subtract one 4-bit binary number from another.
It is implemented using a ripple carry adder, where the subtrahend is complemented and a ‘1’ is added to
perform
2’scomplement
subtraction.
Each full adder processes a pair of bits along with the borrow/carry from the previous stage.
The borrow/carry ripples through all stages, making the circuit simple but slower due to propagation delay.
4 Bit Ripple Carry Adder:
4 Bit Ripple Borrow Subtractor:
Verilog Source Codes:1)4 Bit Ripple Carry Adder:
module fa (a,b,cin,sum,carry);
input a,b,cin;
output sum,carry;
assign sum=a^b^cin;
assign carry=(a&b)+(b&cin)+(cin&a);
endmodule
module b4rpca(a,b,c0,sum,cout);
input [3:0]a,b;
input c0;
output [3:0]sum;
output cout;
wire [2:0]c_temp;
fa f0(a[0],b[0],c0,sum[0],c_temp[0]);
fa f1(a[1],b[1],c_temp[0],sum[1],c_temp[1]);
fa f2(a[2],b[2],c_temp[1],sum[2],c_temp[2]);
fa f3(a[3],b[3],c_temp[2],sum[3],cout);
endmodule
2) 4 Bit Ripple Carry Subtractor
module fa (a,b,cin,sum,carry);
Input a,b,cin;
output sum,carry;
assign sum=a^b^cin;
assign carry=(a&b)+(b&cin)+(cin&a);
endmodule
module b4rpcs(a,b,c0,sum,cout);
input [3:0]a,b;
input c0;
output [3:0]sum;
output cout;
wire [2:0]c_temp;
fa fa0(a[0],~b[0],c0,sum[0],c_temp[0]);
fa fa1(a[1],~b[1],c_temp[0],sum[1],c_temp[1]);
fa fa2(a[2],~b[2],c_temp[1],sum[2],c_temp[2]);
fa fa3(a[3],~b[3],c_temp[2],sum[3],c_out);
endmodule
RTL Schematic:1) 4 Bit Ripple carry Adder:
module b4rpca_tb;
reg [3:0]a,b;
reg c0;
wire [3:0]sum;
wire cout;
b4rpca dut(a,b,c0,sum,cout);
initial
begin
#50 a=4'b0000;b=4'b0000;c0=1'b0;
#50 a=4'b0000;b=4'b0001;c0=1'b0;
#50 a=4'b0000;b=4'b0010;c0=1'b0;
#50 a=4'b0000;b=4'b0011;c0=1'b0;
#50 a=4'b0001;b=4'b0000;c0=1'b0;
#50 a=4'b0001;b=4'b0001;c0=1'b0;
#50 a=4'b0001;b=4'b0010;c0=1'b0;
#50 a=4'b0001;b=4'b0011;c0=1'b0;
end
endmodule
2) 4 Bit Ripple Borrow Subtractor
module b4rpcs_tb;
reg [3:0]a,b;
reg c0;
wire [3:0]sum;
wire cout;
b4rpcs dut(a,b,c0,sum,cout);
initial
begin
#50 a=4'b0000;b=4'b0000;c0=1'b1;
#50 a=4'b0001;b=4'b0000;c0=1'b1;
#50 a=4'b0010;b=4'b0000;c0=1'b1;
#50 a=4'b0011;b=4'b0011;c0=1'b1;
#50 a=4'b0001;b=4'b0000;c0=1'b1;
#50 a=4'b00010;b=4'b0001;c0=1'b1;
#50 a=4'b0011;b=4'b0010;c0=1'b1;
#50 a=4'b0011;b=4'b0001;c0=1'b1;
end
endmodule
Outputs:1) 4 Bit Ripple carry Adder:
Fig 1.5: Output Waveform Of 4 Bit Ripple Carry Adder
2) 4 Bit Ripple Borrow Subtractor
Output Waveform Of 4 Bit Ripple Borrow Adder