You are on page 1of 4

---------------------------------------------------------------------------------- Company: HPES

-- Engineer: Mohd Kashif


--- Create Date:
13:12:30 07/01/2013
-- Design Name: 4-bit ALU
-- Module Name:
ALU - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--- Dependencies:
--- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
---------------------------------------------------------------------------------library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;
use IEEE.numeric_STD.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 ALU is
Port ( a :
b :
z :
sel
l :
g :
e :
end ALU;

in STD_LOGIC_VECTOR (3 downto 0);


in STD_LOGIC_VECTOR (3 downto 0);
out STD_LOGIC_VECTOR (3 downto 0);
: in STD_LOGIC_VECTOR (3 downto 0);
out STD_LOGIC_VECTOR (0 downto 0);
out STD_LOGIC_VECTOR (0 downto 0);
out STD_LOGIC_VECTOR (0 downto 0));

architecture Behavioral of ALU is


begin
process (a,b,sel) is
begin
case sel is
when "0000" =>

z<= a and b;
when "0001" =>
z<= a or b;
when "0010" =>
z<= a xor b;
when "0011" =>
z<= a nand b;
when "0100" =>
z<= a nor b;
when "0101" =>
z<=a+b;
when "0110" =>
z<=a-b;
when "0111" =>
z(3)<=a(2);
z(2)<=a(1);
z(1)<=a(0);
z(0)<= '0';
when "1000" =>
z(0)<=a(1);
Z(1)<=a(2);
z(2)<=a(3);
z(3)<='0';
when "1001" =>
z(0)<=a(3);
z(3)<=a(2);
z(2)<=a(1);
z(1)<=a(0);
when "1010" =>
z(3)<=a(0);
z(2)<=a(3);
z(1)<=a(2);
z(0)<=a(1);
when "1011" =>
z(0)<=a(0);

z(1)<=a(1);
z(2)<=a(2);
z(3)<='0';
when "1100" =>
z(0)<=a(0);
z(1)<=a(1);
z(2)<=b(2);
z(3)<=b(3);
when "1101" =>
if(a>b) then
l(0)<='0';
g(0)<='1';
e(0)<='0';
elsif(a<b) then
l(0)<='1';
g(0)<='0';
e(0)<='0';
elsif(a=b) then
l(0)<='0';
g(0)<='0';
e(0)<='1';
end if;
when "1110" =>
if(a(3)='0' and b(3)='1') then
l(0)<='0';
g(0)<='1';
e(0)<='0';
elsif(a(3)='1' and b(3)='0') then
l(0)<='1';
g(0)<='0';
e(0)<='0';
elsif(a(3)='1' and b(3)='1') then
if(a<b) then
l(0)<='0';
g(0)<='1';
e(0)<='0';
elsif(a>b) then
l(0)<='1';
g(0)<='0';
e(0)<='0';
elsif(a=b) then
l(0)<='0';

g(0)<='0';
e(0)<='1';
end if;
elsif(a(3)='0' and b(3)='0') then
if(a<b) then
l(0)<='1';
g(0)<='0';
e(0)<='0';
elsif(a>b) then
l(0)<='0';
g(0)<='1';
e(0)<='0';
elsif(a=b) then
l(0)<='0';
g(0)<='0';
e(0)<='1';
end if;
end if;
when others =>
z<=a;
end case;
end process;
end Behavioral;

You might also like