library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity haffadd is
Port ( x : in STD_LOGIC;
y : in STD_LOGIC;
s : out STD_LOGIC;
co : out STD_LOGIC);
end haffadd;
architecture Behavioral of haffadd is
begin
s <= x xor y;
co <= x and y;
end Behavioral;
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity fulladd is
Port ( x : in STD_LOGIC;
y : in STD_LOGIC;
cin : in STD_LOGIC;
s : out STD_LOGIC;
co : out STD_LOGIC);
end fulladd;
architecture Behavioral of fulladd is
begin
s <= x xor y xor cin;
co <= (x and y) or (cin and x) or (cin and y);
end Behavioral;
------------------------------------------------------------------------------------
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity all_01 is
Port ( x : in STD_LOGIC_VECTOR (3 downto 0);
y : in STD_LOGIC_VECTOR (3 downto 0);
s : out STD_LOGIC_VECTOR (3 downto 0);
cout : out STD_LOGIC);
end all_01;
architecture Behavioral of all_01 is
signal c1,c2,c3 : std_logic;
component haffadd
Port ( x : in STD_LOGIC;
y : in STD_LOGIC;
s : out STD_LOGIC;
co : out STD_LOGIC);
end component;
component fulladd
Port ( x : in STD_LOGIC;
y : in STD_LOGIC;
cin : in STD_LOGIC;
s : out STD_LOGIC;
co : out STD_LOGIC);
end component;
begin
U1: haffadd port map (x(0),y(0),s(0),c1);
U2: fulladd port map (c1,y(1),x(1),s(1),c2);
U3: fulladd port map (c2,y(2),x(2),s(2),c3);
U4: fulladd port map (c3,y(3),x(3),s(3),cout);
end Behavioral;
No comments:
Post a Comment