Advertisement
Guest User

Untitled

a guest
Jun 28th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.79 KB | None | 0 0
  1. entity ALU is
  2. Port (                  
  3.     clk : in  STD_LOGIC;        
  4.     reset : in  STD_LOGIC;
  5.     operand1: in STD_LOGIC_VECTOR(9 downto 0);
  6.     operand2: in STD_LOGIC_VECTOR(9 downto 0);
  7.     opcode: in STD_LOGIC_VECTOR(4 downto 0);
  8.     result: out STD_LOGIC_VECTOR(9 downto 0);
  9.     status: out STD_LOGIC_VECTOR(1 downto 0));
  10. end ALU;
  11.  
  12. architecture Behavioral of ALU is
  13. signal saida: STD_LOGIC_VECTOR(9 downto 0) := "0000000000";
  14. signal temp_sum: signed(9 downto 0) := "0000000000";
  15. signal saida_status: STD_LOGIC_VECTOR(1 downto 0):= "00";
  16. begin
  17.  
  18.     result <= saida when reset = '0' else "0000000000";
  19.     status <= saida_status when reset = '0' else "00"; 
  20.     saida <=    std_logic_vector(temp_sum);
  21.        
  22.     --status = 01 quando saida eh 0
  23.     --status = 11 quando saida eh negativa
  24.     saida_status <= "01" when saida = "0000000000" else
  25.                          "11" when saida(9) = '1'         else
  26.                          "00";
  27.  
  28.     operacao: process(clk, opcode)
  29.     begin
  30.         if rising_edge(clk) then
  31.             if opcode = "00101" then --00101 = OPcode de soma
  32.                 temp_sum <= signed(operand1) + signed(operand2);
  33.             elsif opcode = "00110" then --00110 = OPcode de subtracao
  34.                 temp_sum <= signed(operand1) - signed(operand2);
  35.             elsif opcode = "00111" then --00111 = OPcode de and logico
  36.                 temp_sum <= signed(operand1) and signed(operand2);
  37.             elsif opcode = "01000" then --01000 = OPcode de or logico
  38.                 temp_sum <= signed(operand1) or signed(operand2);
  39.             elsif opcode = "01001" then --01001 = OPcode de xor logico
  40.                 temp_sum <= signed(operand1) xor signed(operand2);
  41.             elsif opcode = "01010" then --01010  = OPcode de not logico
  42.                 temp_sum <= not signed(operand1);
  43.             elsif opcode = "01011" then --01011  = OPcode de nand logico
  44.                 temp_sum <= signed(operand1) nand signed(operand2);
  45.             end if;
  46.         end if;
  47.     end process operacao;
  48.    
  49.  
  50. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement