 ENTITY RAM IS
 PORT (
       clk    : in bit;
       reset  : in bit;
       addr   : in bit_vector(3 downto 0);
       datain : in bit_vector(3 downto 0);
       csn    : in bit;
       rwn    : in bit;
       dataout: out bit_vector(3 downto 0)
      );
 END RAM;

 ARCHITECTURE MEMORY OF RAM IS
  SIGNAL mem_loc0 : reg_vector(3 downto 0) REGISTER;
  SIGNAL mem_loc1 : reg_vector(3 downto 0) REGISTER;
  SIGNAL mem_loc2 : reg_vector(3 downto 0) REGISTER;
  SIGNAL mem_loc3 : reg_vector(3 downto 0) REGISTER;
  SIGNAL mem_loc4 : reg_vector(3 downto 0) REGISTER;
  SIGNAL mem_loc5 : reg_vector(3 downto 0) REGISTER;
  SIGNAL mem_loc6 : reg_vector(3 downto 0) REGISTER;
  SIGNAL mem_loc7 : reg_vector(3 downto 0) REGISTER;
  SIGNAL mem_loc8 : reg_vector(3 downto 0) REGISTER;
  SIGNAL mem_loc9 : reg_vector(3 downto 0) REGISTER;
  SIGNAL mem_loc10 : reg_vector(3 downto 0) REGISTER;
  SIGNAL mem_loc11 : reg_vector(3 downto 0) REGISTER;
  SIGNAL mem_loc12 : reg_vector(3 downto 0) REGISTER;
  SIGNAL mem_loc13 : reg_vector(3 downto 0) REGISTER;
  SIGNAL mem_loc14 : reg_vector(3 downto 0) REGISTER;
  SIGNAL mem_loc15 : reg_vector(3 downto 0) REGISTER;
  SIGNAL tempout : reg_vector(3 downto 0) REGISTER;
  SIGNAL sel : bit_vector(6 downto 0);

  BEGIN
        dataout <= tempout;
	sel <= reset&csn&rwn&addr;

 L0 : BLOCK (clk ='0' and   not clk'STABLE)
          BEGIN
                  
	WITH sel SELECT 
	mem_loc0 <=   GUARDED
	datain WHEN "1000000",
	mem_loc0 WHEN Others;
           
       WITH sel SELECT 
       mem_loc1 <= GUARDED   
	datain WHEN "1000001",
	 mem_loc1 WHEN Others;
          
       WITH sel SELECT 
       mem_loc2 <= GUARDED   
	datain WHEN "1000010",
	 mem_loc2 WHEN Others;
           
       WITH sel SELECT 
       mem_loc3 <= GUARDED   
	datain WHEN "1000011", 
	 mem_loc3 WHEN Others;
          
       WITH sel SELECT 
       mem_loc4 <= GUARDED   
	datain WHEN "1000100",
	 mem_loc4 WHEN Others;
           
       WITH sel SELECT 
       mem_loc5 <= GUARDED  
	datain WHEN "1000101",
	 mem_loc5 WHEN Others;
          
       WITH sel SELECT 
       mem_loc6 <= GUARDED  
	datain WHEN "1000110",
	 mem_loc6 WHEN Others;
          
 
       WITH sel SELECT 
       mem_loc7 <= GUARDED  
	datain WHEN "1000111",
	 mem_loc7 WHEN Others;
                     
       WITH sel SELECT 
       mem_loc8 <= GUARDED  
	datain WHEN "1001000",
	 mem_loc8 WHEN Others;
            
          
       WITH sel SELECT 
       mem_loc9 <= GUARDED  
	datain WHEN "1001001",
	 mem_loc9 WHEN Others;
           
       WITH sel SELECT 
       mem_loc10 <= GUARDED  
	datain WHEN "1001010", 
	 mem_loc10 WHEN Others;
	          
       WITH sel SELECT 
       	mem_loc11 <= GUARDED  
	datain WHEN "1001011",
 	mem_loc11 WHEN Others;
          

       WITH sel SELECT 
       mem_loc12 <= GUARDED  
	datain WHEN "1001100",
	 mem_loc12 WHEN Others;
          

       WITH sel SELECT 
       mem_loc13 <= GUARDED  
	datain WHEN "1001101",
	 mem_loc13 WHEN Others;
          

       WITH sel SELECT 
       mem_loc14 <= GUARDED  
	datain WHEN "1001110",
	 mem_loc14 WHEN Others;
           

       	WITH sel SELECT 
       	mem_loc15 <= GUARDED  
	datain WHEN "1001111",
	mem_loc15 WHEN Others;
    
   END BLOCK;
         

  L1 : BLOCK (clk ='0' and   not clk'STABLE)
          BEGIN
        WITH sel SELECT
            tempout <= GUARDED   
                       mem_loc0 WHEN "1010000",
                       mem_loc1 WHEN "1010001",
                       mem_loc2 WHEN "1010010",
                       mem_loc3 WHEN "1010011",
                       mem_loc4 WHEN "1010100",
                       mem_loc5 WHEN "1010101",
                       mem_loc6 WHEN "1010110",
                       mem_loc7 WHEN "1010111",
                       mem_loc8 WHEN "1011000",
                       mem_loc9 WHEN "1011001",
                       mem_loc10 WHEN "1011010",
                       mem_loc11 WHEN "1011011",
                       mem_loc12 WHEN "1011100",
                       mem_loc13 WHEN "1011101",
                       mem_loc14 WHEN "1011110",
                       mem_loc15 WHEN "1011111",
                      "1111" WHEN OTHERS ;
         END BLOCK;
END;

 
