No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

alu.vhd 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 10:12:38 04/13/2021
  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. -- Uncomment the following library declaration if using
  24. -- arithmetic functions with Signed or Unsigned values
  25. use IEEE.NUMERIC_STD.ALL;
  26. -- Uncomment the following library declaration if instantiating
  27. -- any Xilinx primitives in this code.
  28. --library UNISIM;
  29. --use UNISIM.VComponents.all;
  30. entity alu is
  31. Port ( A : in STD_LOGIC_VECTOR (7 downto 0);
  32. B : in STD_LOGIC_VECTOR (7 downto 0);
  33. Ctrl_Alu : in STD_LOGIC_VECTOR (2 downto 0);
  34. N : out STD_LOGIC;
  35. O : out STD_LOGIC;
  36. Z : out STD_LOGIC;
  37. C : out STD_LOGIC;
  38. S : out STD_LOGIC_VECTOR (7 downto 0));
  39. end alu;
  40. architecture Behavioral of alu is
  41. signal A9: STD_LOGIC_VECTOR(8 downto 0);
  42. signal B9: STD_LOGIC_VECTOR(8 downto 0);
  43. signal ADD: STD_LOGIC_VECTOR(8 downto 0);
  44. signal SUB: STD_LOGIC_VECTOR(8 downto 0);
  45. signal MUL: STD_LOGIC_VECTOR(15 downto 0);
  46. signal SBIS: STD_LOGIC_VECTOR(7 downto 0);
  47. begin
  48. A9 <= "0"& A;
  49. B9 <= "0"& B;
  50. ADD <= A9 + B9;
  51. SUB <= A9 - B9;
  52. MUL <= A * B;
  53. SBIS <= ADD(7 downto 0) when Ctrl_Alu = "001" else
  54. SUB(7 downto 0) when Ctrl_Alu = "010" else
  55. MUL(7 downto 0) when Ctrl_Alu = "011" else
  56. (others => '0');
  57. O <= '1' when MUL(15 downto 8) /= "00000000" and Ctrl_Alu = "011" else
  58. '0';
  59. C <= '1' when ADD(8) = '1' and Ctrl_Alu = "001" else
  60. '0';
  61. N <= '1' when SUB(8) = '1' and Ctrl_Alu = "010" else
  62. '0';
  63. Z <= '1' when SBIS = "00000000" and Ctrl_Alu /= "000" else
  64. '0';
  65. S <= SBIS;
  66. end Behavioral;