Trying to verify Verilog/VHDL designs with formal methods and tools
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.

54 lines
1.3 KiB

6 years ago
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. entity alu is
  5. port (
  6. Reset_n_i : in std_logic;
  7. Clk_i : in std_logic;
  8. Opc_i : in std_logic_vector(1 downto 0);
  9. DinA_i : in std_logic_vector(31 downto 0);
  10. DinB_i : in std_logic_vector(31 downto 0);
  11. Dout_o : out std_logic_vector(31 downto 0);
  12. OverFlow_o : out std_logic
  13. );
  14. end entity alu;
  15. architecture rtl of alu is
  16. constant c_add : std_logic_vector(1 downto 0) := "00";
  17. constant c_sub : std_logic_vector(1 downto 0) := "01";
  18. constant c_and : std_logic_vector(1 downto 0) := "10";
  19. constant c_or : std_logic_vector(1 downto 0) := "11";
  20. begin
  21. process (Reset_n_i, Clk_i) is
  22. begin
  23. if (Reset_n_i = '0') then
  24. Dout_o <= (others => '0');
  25. elsif (rising_edge(Clk_i)) then
  26. case Opc_i is
  27. when c_add => (OverFlow_o, Dout_o) <=
  28. std_logic_vector(resize(unsigned(DinA_i), Dout_o'length+1) +
  29. resize(unsigned(DinB_i), Dout_o'length+1));
  30. when c_sub => (OverFlow_o, Dout_o) <=
  31. std_logic_vector(resize(unsigned(DinA_i), Dout_o'length+1) -
  32. resize(unsigned(DinB_i), Dout_o'length+1));
  33. when c_and => Dout_o <= DinA_i and DinB_i;
  34. when c_or => Dout_o <= DinA_i or DinB_i;
  35. when others => null;
  36. end case;
  37. end if;
  38. end process;
  39. end architecture rtl;