CO Expt No. 4
CO Expt No. 4
AIM: To study and execute VHDL code for 4 bit Ripple Carry Adder.
THEORY:
In digital electronics adding of two-bit binary numbers can be possible by using half
adder. And if the input sequence has a three-bit sequence, then the addition process can be
completed by using a full adder. But if the numbers of bits are more in the input sequence
then the process can be completed by using half adder. Because full adder cannot be able to
complete the addition operation. So these drawbacks can be overcome by using “Ripple
Carry Adder”. It’s a unique type of logic circuit used for adding the N-bit numbers in digital
operations. This article describes an overview of what is ripple-carry-adder and its operation.
1|Page
Working of 4-bit Ripple Carry Adder:
1. Let’s take an example of two input sequences 0101 and 1010. These are representing
the A4 A3 A2 A1 and B4 B3 B2 B1.
2. As per this adder concept, input carry is 0.
3. When Ao & Bo are applied at 1st full adder along with input carry 0.
4. Here A1 =1 ; B1=0 ; Cin=0
5. Sum (S1) and carry (C1) will be generated as per the Sum and Carry equations of this
adder. As per its theory, the output equation for the Sum = A1⊕B1⊕Cin and Carry =
A1B1⊕B1Cin⊕CinA1
6. As per this equation, for 1st full adder S1 =1 and Carry output i.e., C1=0.
7. Same like for next input bits A2 and B2, output S2 = 1 and C2 = 0. Here the important
point is the second stage full adder gets input carry i.e., C1 which is the output carry
of initial stage full adder.
8. Like this will get the final output sequence (S4 S3 S2 S1) = (1 1 1 1) and Output carry
C4 = 0
9. This is the addition process for 4-bit input sequences when it’s applied to this carry
adder.
2|Page
Disadvantages of Ripple Carry Adder:
Ripple Carry Adder does not allow to use all the full adders simultaneously.
Each full adder has to necessarily wait until the carry bit becomes available from its
adjacent full adder.
This increases the propagation time.
Due to this reason, ripple carry adder becomes extremely slow.
This is considered to be the biggest disadvantage of using ripple carry adder.
PROGRAM:
DESIGN:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
--entity declaration with port definitions
entity rc_adder is
port( num1 : in std_logic_vector(3 downto 0); --4 bit input 1
num2 : in std_logic_vector(3 downto 0); -- 4 bit input 2
sum : out std_logic_vector(3 downto 0); -- 4 bit sum
carry : out std_logic -- carry out.
);
end rc_adder;
--architecture of entity
architecture Behavioral of rc_adder is
--temporary signal declarations(for intermediate carry's).
signal c0,c1,c2,c3 : std_logic := '0';
begin
--first full adder
sum(0) <= num1(0) xor num2(0); --sum calculation
c0 <= num1(0) and num2(0); --carry calculation
--second full adder
sum(1) <= num1(1) xor num2(1) xor c0;
c1 <= (num1(1) and num2(1)) or (num1(1) and c0) or (num2(1) and c0);
3|Page
--third full adder
sum(2) <= num1(2) xor num2(2) xor c1;
c2 <= (num1(2) and num2(2)) or (num1(2) and c1) or (num2(2) and c1);
--fourth(final) full adder
sum(3) <= num1(3) xor num2(3) xor c2;
c3 <= (num1(3) and num2(3)) or (num1(3) and c2) or (num2(3) and c2);
--final carry assignment
carry <= c3;
end Behavioral;
TESTBENCH:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
--this is how entity for your test bench code has to be declared.
entity testbench is
end testbench;
4|Page
wait for 2 ns;
num1<="1010"; --num1 =10
num2<="0011"; --num2 =3
wait for 2 ns;
num1<="1010"; --num1=10
num2<="0101"; --num2 =5
wait for 2 ns;
num1<="1001";--num1 =9
num2<="0111"; --num2 =7
--more input combinations can be given here.
wait for 2 ns;
wait;
end process tb;
end;
OUTPUT:
5|Page
CONCLUSION:
6|Page