Professional Documents
Culture Documents
entity ALU_64 is
generic(n:integer:=8);
Port ( A : in STD_LOGIC_VECTOR (n-1 downto 0);
B : in STD_LOGIC_VECTOR (n-1 downto 0);
clk:in std_logic;
S:in std_logic_vector(3 downto 0);---carry in is bit S(0);
F : out STD_LOGIC_VECTOR (n-1 downto 0);
component logical_unit
generic(n:integer:=8);
Port ( A : in STD_LOGIC_VECTOR (n-1 downto 0);
B : in STD_LOGIC_VECTOR (n-1 downto 0);
s : in STD_LOGIC_VECTOR (2 downto 0);
clk : in STD_LOGIC;
end Behavioral;
-------------------------------------------------------------------------------
Logical unit..
-------------------------------------------------------------------------------library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_1164.all;
entity logical_unit is
generic(n:integer:=8);
Port ( A : in STD_LOGIC_VECTOR (n-1 downto 0);
case s is
when "000" => F<= A and B;
when "001" => F<= A or B;
when "010" => F<= A xor B;
when "011" => F<= A nand B;
when "100" => F<= not A;
when "101" => F<= '0'& A(n-1 downto 1);--shift right-when "110" => F<= A(n-2 downto 0)&'0';--shift left-when "111" => F<= ('0'& A(n-1 downto 1)) or A1;
when others=> NULL;
end case;
end process;
end Behavioral;
entity Arith_unit is
generic(n:integer:=8);
Port ( A : in STD_LOGIC_VECTOR (n-1 downto 0):=(others=>'0');
begin
a1<= '0'& A;
b1<= '0'& B;
process(clk)
begin
case s is
when "000" => f1<=a1;
when "001" => f1<=a1 + 1;
when "010" => f1<=a1+ b1 ;
when "011" => f1<=a1+ b1 + 1;
when "100" => f1<=a1 - b1 - 1;
when "101" => f1<=a1 - b1;
end process;
end Behavioral;
---------------------------------------------------------------------------
MUX 2:1
---------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
end mux2;
begin
process(clk)
begin
case s3 is
when '0'=> Y<=F1;
when '1' => Y<=F2;
when others=> NULL;
end case;
end process;
end Behavioral;
****************************************************************************