public static int[] access(int[] a,int[] reg,int rw)
	{
		int[] r=new int[ARRAY_ROWS];
		int[] b1=new int[WORD_SIZE];

		
		//generate row selects	(and-circuit)
		for(int row=0;row<ARRAY_ROWS;row++)
		{
			int mask=4;
				
			r[row]=Function.and(Function.C_MEMORY,(row&1)>0?a[0]:Function.not(Function.C_MEMORY,a[0]),(row&2)>0?a[1]:Function.not(Function.C_MEMORY,a[1]));				
			for(int m=2;m<ARRAY_COLS;m++,mask<<=1)
				r[row]=Function.and(Function.C_MEMORY,r[row],(row&mask)>0?a[m]:Function.not(Function.C_MEMORY,a[m]));
		}
		
		//write into selected cells (reg=cell=(cell & !read | reg & read))
		for(int row=0;row<ARRAY_ROWS;row++)
		{
			for(int i=0;i<8;i++)
				cellarray[row][i]=Function.xor(Function.C_MEMORY,Function.and(Function.C_MEMORY,r[row],Function.not(Function.C_MEMORY,rw),reg[i]),
											   Function.and(Function.C_MEMORY,r[row],rw,cellarray[row][i]),
											   Function.and(Function.C_MEMORY,Function.not(Function.C_MEMORY,r[row]), cellarray[row][i]));
//			for(int i=8;i<ARRAY_COLS;i++)
//				cellarray[row][i]=Function.or(Function.and(r[row],Function.not(rw),reg[i]),
//											  Function.and(r[row],rw,cellarray[row][i]),
//											  Function.and(Function.not(r[row]), cellarray[row][i]));
		}
//		System.out.println();
		//combine row signals and cell bits (or-circuit)
		//load b1
		for(int i=0;i<WORD_SIZE;i++)
		{
			b1[i]=Function.xor(Function.C_MEMORY,Function.and(Function.C_MEMORY,r[0],cellarray[0][i]),Function.and(Function.C_MEMORY,r[1],cellarray[1][i]));
			for(int j=2;j<ARRAY_ROWS;j++)
				b1[i]=Function.xor(Function.C_MEMORY,b1[i],Function.and(Function.C_MEMORY,r[j],cellarray[j][i]));
		}
		
		return b1;
	}