⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 add_32_bcd.txt

📁 此程序采用VHDL语言
💻 TXT
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity eecadd_32 is
port( a: in std_logic_vector(31 downto 0);
    b: in std_logic_vector(31 downto 0);
    cin:in std_logic;
    bcdout: out std_logic_vector(31 downto 0);
    cout:out std_logic );
end eecadd_32;
architecture arch of eecadd_32 is
  signal co:std_logic_vector(31 downto 0);
  signal y:std_logic_vector(31 downto 0);
  begin
     y(0)<=a(0)xor b(0)xor cin;
     co(0)<=(a(0)and b(0))or(b(0)and cin)or(a(0)and cin);
       gen:for I in 1 to 31 generate
          y(I)<=a(I)xor b(I)xor co(I-1);
          co(I)<=(co(I-1)and a(I)) or (co(I-1)and b(I))or (a(I)and b(I));
     end generate;
 process(a,b,y,co(31))
    procedure bcd_change(data_in:inout std_logic_vector(3 downto 0);
                         data_cin:in std_logic;
                         data_out:out std_logic_vector(3 downto 0);
                         data_cout:out std_logic)is
    begin
      if(data_in>"1001")then
      data_out:=data_in+"0110";
      data_cout:='1';
      elsif(data_cin='1')then
      data_out:=data_in+"0110";
      data_cout:='0';
      else
      data_out:=data_in;
      data_cout:='0';
      end if;
    end bcd_change;
    variable d,e,coo:std_logic_vector(31 downto 0);
    variable f,g,h,i,m,n,f0,g0,h0,i0,m0,n0,j,k:std_logic_vector(3 downto 0);
    variable s:std_logic_vector(14 downto 0);
	begin
     d:=y;
     coo:=co;
     bcd_change(d(3 downto 0),coo(3),e(3 downto 0),s(0));
     f:="000"&s(0);
     if(d(7 downto 4)="1111")then
     s(1):='1';
     else
     s(1):=coo(7);
     end if;
     g:=d(7 downto 4)+f;
     bcd_change(g,s(1),e(7 downto 4),s(2));
     h:="000"&s(2);
     if(d(11 downto 8)="1111")then
     s(3):='1';
     else
     s(3):=coo(11);
     end if;
     i:=d(11 downto 8)+h;
     bcd_change(i,s(3),e(11 downto 8),s(4));
     m:="000"&s(4);
     if(d(15 downto 12)="1111")then
     s(5):='1';
     else
     s(5):=coo(15);
     end if;
     n:=d(15 downto 12)+m;
     bcd_change(n,s(5),e(15 downto 12),s(6));
     f0:="000"&s(6);
     if(d(19 downto 16)="1111")then
     s(7):='1';
     else
     s(7):=coo(19);
     end if;
     g0:=d(19 downto 16)+f0;
     bcd_change(g0,s(7),e(19 downto 16),s(8));
     h0:="000"&s(8);
     if(d(23 downto 20)="1111")then
     s(9):='1';
     else
     s(9):=coo(23);
     end if;
     i0:=d(23 downto 20)+h0;
     bcd_change(i0,s(9),e(23 downto 20),s(10));
     m0:="000"&s(10);
     if(d(27 downto 24)="1111")then
     s(11):='1';
     else
     s(11):=coo(27);
     end if;
     n0:=d(27 downto 24)+m0;
     bcd_change(n0,s(11),e(27 downto 24),s(12));
     j:="000"&s(12);
     if(d(31 downto 28)="1111")then
     s(13):='1';
     else
     s(13):=coo(31);
     end if;
     k:=d(31 downto 28)+j;
     bcd_change(k,s(13),e(31 downto 28),s(14));
     bcdout<=e;
     cout<=s(14) or co(31);          
end process;
end arch;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -