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.

registers.vhd 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  4. use IEEE.NUMERIC_STD.ALL;
  5. entity registers is
  6. Port ( addr_A : in STD_LOGIC_VECTOR (3 downto 0);
  7. addr_B : in STD_LOGIC_VECTOR (3 downto 0);
  8. addr_W : in STD_LOGIC_VECTOR (3 downto 0);
  9. W : in STD_LOGIC;
  10. DATA : in STD_LOGIC_VECTOR (7 downto 0);
  11. RST : in STD_LOGIC;
  12. CLK : in STD_LOGIC;
  13. QA : out STD_LOGIC_VECTOR (7 downto 0);
  14. QB : out STD_LOGIC_VECTOR (7 downto 0));
  15. end registers;
  16. architecture Behavioral of registers is
  17. type REGISTER_BANK is array (15 downto 0) of std_logic_vector(7 downto 0);
  18. SIGNAL RB : REGISTER_BANK;
  19. begin
  20. process
  21. begin
  22. wait until CLK'event and CLK='1';
  23. if (RST = '0') then
  24. RB <= (others => (others => '0'));
  25. elsif (W = '1') then
  26. RB(to_integer(unsigned(addr_W))) <= DATA;
  27. end if;
  28. end process;
  29. QA <= RB(to_integer(unsigned(addr_A))) when W = '0' or addr_W /= addr_A else DATA;
  30. QB <= RB(to_integer(unsigned(addr_B))) when W = '0' or addr_W /= addr_B else DATA;
  31. end Behavioral;