VHDL Code for BCD Adder

Binary Coded Decimal : for more: Click here

  • It is another way to represent decimal numbers. It is important because many digital devices display their results in tens.
  • In BCD each number is defined by binary code of 4 BITS.
  • 8-4-2-1 code indicates the weight of each bit.
  • 925 = 1001 0010 0101

BCD Adder :

BCD adder A 4-bit binary adder that is capable of adding two 4-bit words having a BCD (binary-coded decimal) format. The result of the addition is a BCD-format 4-bit output word, representing the decimal sum of the addend
and augend, and a carry that is generated if this sum exceeds a decimal value of 9. Decimal addition is thus possible using these devices.


library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity bcd_adder is
    port( a,b  : in  unsigned(3 downto 0);
       carry_in : in std_logic;
        sum  : out  unsigned(3 downto 0); 
        carry : out std_logic  
end bcd_adder;

architecture arch of bcd_adder is


variable sum_temp : unsigned(4 downto 0);
    sum_temp := ('0& a) + ('0& b) + ("0000" & carry_in); 
    if(sum_temp > 9) then
        carry <= '1';
        sum <= resize((sum_temp + "00110"),4);
        carry <= '0';
        sum <= sum_temp(3 downto 0);
    end if; 
end process;   

end architecture;

No comments:

Post a Comment