Advertisement
Randune1

DataMem

Jan 12th, 2023 (edited)
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.20 KB | Source Code | 0 0
  1. entity DataMem is
  2.    port(
  3.       Clk      : in  std_logic;
  4.       INW0     : in  std_logic_vector(15 downto 0);
  5.       INW1     : in  std_logic_vector(15 downto 0);      
  6.       OUTW0    : out std_logic_vector(15 downto 0);
  7.      
  8.       Wr       : in  std_logic;
  9.       Addr     : in  std_logic_vector(4 downto 0);
  10.       DataIn   : in  std_logic_vector(15 downto 0);        
  11.       DataOut  : out std_logic_vector(15 downto 0)  
  12.      
  13.    );
  14. end DataMem;
  15.  
  16. architecture Behavioral of DataMem is
  17.    type RAM16x16  is array (0 to 15) of std_logic_vector(15 downto 0);
  18.    signal RAM     : RAM16x16;
  19.    signal MemData : std_logic_vector(15 downto 0);
  20. begin
  21.    process(Clk)
  22.    begin
  23.       if rising_edge(Clk) then
  24.          if (Wr='1' and Addr(4) = '0') then
  25.             RAM(conv_integer(Addr(3 downto 0))) <= DataIn;
  26.          end if;  
  27.       end if;
  28.    end process;
  29.    
  30.    MemData  <= RAM(conv_integer(Addr(3 downto 0)));
  31.    
  32.    DataOut  <= MemData  when Addr(4)='0' else
  33.                INW0   when Addr(1 downto 0)=0 else
  34.                INW1   ;
  35.                
  36.    OUTW0    <= DataIn when rising_edge(Clk) and Addr(4)='1' and Addr(1)='1' and Wr='1';            
  37.                
  38. end Behavioral;
  39.  
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement