Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 11:03:43 01/18/2019
  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. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  23.  
  24. -- Uncomment the following library declaration if using
  25. -- arithmetic functions with Signed or Unsigned values
  26. --use IEEE.NUMERIC_STD.ALL;
  27.  
  28. -- Uncomment the following library declaration if instantiating
  29. -- any Xilinx primitives in this code.
  30. --library UNISIM;
  31. --use UNISIM.VComponents.all;
  32.  
  33. entity ALU is
  34. Port ( iA : in STD_LOGIC_VECTOR (15 downto 0);
  35. iB : in STD_LOGIC_VECTOR (15 downto 0);
  36. iSEL : in STD_LOGIC_VECTOR (3 downto 0);
  37. oC : out STD_LOGIC_VECTOR (15 downto 0);
  38. oSIGN : out STD_LOGIC;
  39. oCARRY : out STD_LOGIC;
  40. oZERO : out STD_LOGIC);
  41. end ALU;
  42.  
  43. architecture Behavioral of ALU is
  44. signal sC : STD_LOGIC_VECTOR (16 downto 0);
  45. signal sA : STD_LOGIC_VECTOR (16 downto 0);
  46. signal sB : STD_LOGIC_VECTOR (16 downto 0);
  47. begin
  48. sA <= '0' & iA(15 downto 0);
  49. sB <= '0' & iB(15 downto 0);
  50.  
  51. sC <= sA when iSEL="0000" else
  52. sA+sB when iSEL="0001" else
  53. sA-sB when iSEL="0010" else
  54. sA and sB when iSEL="0011" else
  55. sA or sB when iSEL="0100" else
  56. not(sA) when iSEL="0101" else
  57. sA + 1 when iSEL="0110" else
  58. sA - 1 when iSEL="0111" else
  59. '0' & sA(14 downto 0) & '0' when iSEL="1000" else
  60. '0' & '0' & sA(14 downto 0) when iSEL="1001" else
  61. not(sA) + 1 when iSEL="1010" else
  62. sA(16 downto 15) & sA(15 downto 1) when iSEL="1011" else
  63. "00000000000000000";
  64.  
  65. oZERO <= '1' when sC = "00000000000000000" else '0';
  66. oCARRY <= sC(16);
  67. oSIGN <= sC(15);
  68. oC <= sC(15 downto 0);
  69. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement