library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity add is
port(clr,en,clkin:in std_logic; ---------清零,使能及触发时钟
a,b:in std_logic_vector(9 downto 0);---------加数
c:out std_logic_vector(9 downto 0);----------和
ci:out std_logic ---------进位
);
end add;
architecture arch of add is
---------;
signal reg:std_logic_vector(10 downto 0):="00000000000";
----------------------------------------------------------------------------
begin
----------------
process(clr,clkin,en,a,b)
begin
if(clr='0') then --------------异步清零
reg<="00000000000";
elsif(clkin'event and clkin='1') then
if(en='1')then -------------同步使能
reg<=('0'&a)+('0'&b); ---------求和
end if;
end if;
end process;
---------------
c<=reg(9 downto 0); ----------赋值给和
ci<=reg(10); ----------赋值给进位
---------------------------------------------------------------------
end arch;