⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ram.txt

📁 a 16 by 4 ram is used for many applications as a basic component such as fifo and stack etc
💻 TXT
字号:
---------------------------------ram------------------------------

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ram16by4 is
    Port ( rw : in std_logic;
           en_l : in std_logic;
           datain : in std_logic_vector(3 downto 0);
           addr : in std_logic_vector(3 downto 0);
           dataout : out std_logic_vector(3 downto 0));
end ram16by4;

architecture Behavioral of ram16by4 is
  subtype wtype is STD_LOGIC_VECTOR (3 downto 0);
  type mem_type is array (15 downto 0) of wtype;
   signal memory:mem_type;
 function conv_integer(x:std_logic_vector) return integer is
    variable result:integer;
   begin
         result:=0;
      for i in x'range loop
		if X(i)='1'
		 then   result:= result+2**i;
       else null;
       end if;
      end loop;
    return result;
   end conv_integer;
 begin
 process(en_l,rw,addr)
 begin
     if(en_l='0') then
       if (rw ='0') then 
        memory(conv_integer(addr))<= datain;
        dataout<="ZZZZ"; 
		  elsif (rw ='1') then
        dataout<=not memory(conv_integer(addr));
       end if; 
       else
        dataout<=(others=>'Z'); 
     end if;
 end process;
end Behavioral;


---------------------------test bench---------------------------
------------------it is in my record ra---------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -