VHDL code for Carry Look Ahead adder

The simplest form of adder is Ripple carry adder. But sometimes we might need adders which are faster than that. That is when Carry look ahead adders come to the rescue.

By calculating all the carry's in advance, this type of adder achieves lower propagation delays and thus higher performance. The disadvantage comes from the fact that, as the size of inputs goes beyond 4 bits, the adder becomes much more complex.

In this post I have written the VHDL code for a 4 bit carry look ahead adder. For the block diagram and explanation of the logic, you might want to see pages 1 to 3 in this pdf.

cla_adder.vhd

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity cla_adder is
port( A,B : in std_logic_vector(3 downto 0);
        cin : in std_logic;
        S : out std_logic_vector(3 downto 0);
        cout : out std_logic
        );
end cla_adder;

architecture Behavioral of cla_adder is

signal P,G : STD_LOGIC_VECTOR(3 DOWNTO 0) := "0000";
signal C : STD_LOGIC_VECTOR(4 DOWNTO 0) := "00000";

component cla_block is
port (
      P : in std_logic_vector(3 downto 0);
      G : in std_logic_vector(3 downto 0);
     C : out std_logic_vector(4 downto 0);
     cin : in std_logic
     );
end component;

begin

--first level
<= A xor B;
<= A and B;

--second level
gen_c : cla_block port map(P,G,C,cin);

--third level
<= P xor C(3 downto 0);
cout <= C(4);

end Behavioral;


cla_block.vhd

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity cla_block is
port (
      P : in std_logic_vector(3 downto 0);
      G : in std_logic_vector(3 downto 0);
     C : out std_logic_vector(4 downto 0);
     cin : in std_logic
     );
end cla_block;

architecture Behavioral of cla_block is
begin

C(0) <= cin;
C(1) <= G(0) or (P(0) and cin);
C(2) <= G(1) or (P(1) and G(0)) or (P(1) and P(0) and cin);
C(3) <= G(2) or (P(2) and G(1)) or (P(2) and P(1) and G(0)) or (P(2) and P(1) and P(0) and cin);
C(4) <= G(3) or (P(3) and G(2)) or (P(3) and P(2) and G(1)) or (P(3) and P(2) and P(1) and G(0)) or (P(3) and P(2) and P(1) and P(0) and cin);
 
end Behavioral;



Testbench code:

I have used the same testbench code(tb_adder.vhd), at the bottom of this post. But make sure you change the name of the initiated entity.

Simulated waveform:

The waveform should look like this. The code checks for all the input combinations and the signal "error" shows the number of errors. If all goes well, "error" signal should remain at zero.



Related Posts :

7 Responses to "VHDL code for Carry Look Ahead adder "

  1. This comment has been removed by the author.

    ReplyDelete
  2. The students will be able to check their UP Board Result for Class 12 via SMS also. The UP Board 12th Result 2021 would comprise the student's roll number, name, subject-wise marks among other details. Around 25 lakh students will be able to check their UP Board Result 2021 Class 12 for the UP 12th examination which will be conducted in April and May 2021. As soon as the UP Board Result 2021 Uttar Pradesh 12th Result 2021 ​is announced, the official website might crash or not load due to heavy traffic, in such a case, students must not panic and wait patiently to check their UP MSP Results 2021 for Class 12.

    ReplyDelete
  3. Aksaray Escort
    To say the truth I am very impressed by what you told. You share tons of interesting info, neat and excellent design you’ve got here. It’s certainly one of the most informative stuff on this topic I’ve ever read.

    ReplyDelete
  4. Damascus Wedding Band
    I’m excited to uncover this page. I need to to thank you for ones time for this particularly fantastic read!! I definitely really liked every part of it and i also have you saved to fav to look at new information in your site

    ReplyDelete
  5. Tungsten Wood Bands
    Wonderful blog post. This is absolute magic from you! I have never seen a more wonderful post than this one. You've really made my day today with this. I hope you keep this up!

    ReplyDelete
  6. Many thanks foCohiba Medio SigloMany thanks for the exciting blog posting! Simply put your blog post to my favorite blog list and will look forward for additional updates. Simply wanted to write down a word in order to say thanks to you for those wonderful tips.
    r the exciting blog posting! Simply put your blog post to my favorite blog list and will look forward for additional updates. Simply wanted to write down a word in order to say thanks to you for those wonderful tips.

    ReplyDelete
  7. Totally loved your article. Looking forward to see more more from you. Meanwhile feel free to surf through my website while i give your blog a read.

    pug puppies for sale
    pug puppies for sale
    Pug Puppies For sale near me
    Pug puppies Near Me

    ReplyDelete