以VHDL语言编写一个模块,实现一个多功能计数器,可实现加法、减法、乘法和除法功能。请提供完整的VHDL代码。

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity counter is
  port (
    enable : in std_logic;
    rst : in std_logic;
    clk : in std_logic;
    mode : in std_logic_vector(1 downto 0);
    input1 : in integer range 0 to 15;
    input2 : in integer range 0 to 15;
    result : out integer range 0 to 15
  );
end entity counter;

architecture Behavioral of counter is
  signal count_reg : integer range 0 to 15 := 0;
begin
  process (clk)
  begin
    if rising_edge(clk) then
      if rst = '1' then
        count_reg <= 0;
      elsif enable = '1' then
        case mode is
          when "00" => count_reg <= count_reg + input1;
          when "01" => count_reg <= count_reg - input2;
          when "10" => count_reg <= count_reg * input1;
          when others =>
            if input2 /= 0 then
              count_reg <= count_reg / input2;
            end if;
        end case;
      end if;
    end if;
  end process;
  result <= count_reg;
end architecture Behavioral;