Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 03/09/2018 11:50:18 AM
  6. -- Design Name:
  7. -- Module Name: ALU - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool Versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20.  
  21.  
  22.  
  23. library IEEE;
  24. use IEEE.STD_LOGIC_1164.ALL;
  25. use IEEE.STD_LOGIC_ARITH.ALL;
  26. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  27.  
  28. -- Uncomment the following library declaration if using
  29. -- arithmetic functions with Signed or Unsigned values
  30. --use IEEE.NUMERIC_STD.ALL;
  31.  
  32. -- Uncomment the following library declaration if instantiating
  33. -- any Xilinx leaf cells in this code.
  34. --library UNISIM;
  35. --use UNISIM.VComponents.all;
  36.  
  37. entity ALU is
  38. Port ( a : in std_logic_vector(15 downto 0);
  39. b : in std_logic_vector(15 downto 0);
  40. sa: in std_logic;
  41. OP : in STD_LOGIC_VECTOR(3 downto 0);
  42. AluRes : out STD_LOGIC_VECTOR (15 downto 0);
  43. zero : out STD_LOGIC);
  44. end ALU;
  45.  
  46. architecture Behavioral of ALU is
  47.  
  48. signal lshift : std_logic_vector(15 downto 0);
  49. signal rshift : std_logic_vector(15 downto 0);
  50.  
  51. signal result : std_logic_vector(15 downto 0);
  52.  
  53. begin
  54.  
  55. process(a,b,sa)
  56. begin
  57.  
  58. if(sa = '1')then
  59. lshift <= a(14 downto 0) & "0";
  60. rshift <= "0" & a(15 downto 1);
  61.  
  62. else
  63. lshift <= a ;
  64. rshift <= a ;
  65. end if;
  66. end;
  67.  
  68.  
  69. process(OP)
  70. begin
  71. case (OP) is
  72. when "0000" => result <= a + b;
  73. when "0001" => result <= a - b;
  74. when "0010" => result <= lshift;
  75. when "0011" => result <= rshift;
  76. when "0100" => result <= a and b; -- for load / store
  77. when "0101" => result <= a or b;
  78. when "0110" => result <= a xor b;
  79. when "0111" => result <= a * b;
  80. when "1000" => result <= b;
  81. when others => result <=x"0000";
  82. end case;
  83. end process;
  84.  
  85. zero <= '1' when result = "0000000000000000" else '0';
  86. AluRes <= result;
  87. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement