www.pudn.com > codeofvhdl2006.rar > BCDADD.VHD


--bcdadd.vhd 1 digit bcd adder 
library ieee ; 
use ieee.std_logic_1164.all; 
use work.components.all; 
entity bcdadd is 
port( 
  	a	: in std_logic_vector(3 downto 0);--被加數 
	b 	: in std_logic_vector(3 downto 0);--加數 
  	ci 	: in std_logic;--進位輸入 
  	co 	: out std_logic;--進位輸出 
  	sum : out std_logic_vector(3 downto 0));--和 
end bcdadd; 
architecture behavior of bcdadd is  
  signal s : std_logic_vector(3 downto 0); --第一個fadd4的和 
  signal c4 : std_logic;--第一個fadd4進位輸出 
  signal a2 : std_logic_vector(3 downto 0); 
  signal y : std_logic;--加6偵測內部連線 
  signal zero : std_logic;--第二個fadd4的進位保持'0' 
  signal nouse : std_logic;--沒有使用到的浮接線 
begin  
  u0: fadd4 port map (a,b,ci,c4,s);--第1個fadd4 
  y<=c4 or (s(3) and s(2)) or (s(3) and s(1));--偵測加6 
  a2<='0' & y & y & '0'; 
  co<=y;--bcd進位輸出 
  zero<='0'; --第二個fadd4的進位保持'0' 
  u1: fadd4 port map (a2,s,zero,nouse,sum);--第2個fadd4 
end behavior;