memory to cache problem
hi
i have a memory class and a cache class
i want to write a main class transfering data from the memory to the cache using direct mapping
if anybody could help me writing this id appreciate it very much
thanks
the code is below
memory class
publicclass Memory
{
int[][] memoryArray;
public Memory()
{
int[][] memoryArray=newint[50][8];
Random randnum =new Random();
for(int i=0;i<50;i++)
{
for(int j=0;j<8;j++)
{
memoryArray[i][j]=randnum.nextInt(1023);
}
}
for(int i=0;i<50;i++)
{
System.out.print("|["+i+"] ");
for(int j=0;j<8;j++)
{
// System.out.print(memoryArray[i][j] + " ");
System.out.printf("%5d |", memoryArray[i][j]);
}
System.out.println();
System.out.print("-");
System.out.println();
}
}
publicint[][] getMemoryLocation(int address)
{
int a = address;
int [][]memoryAddress =newint[1][8];
for(int i=0; i<8;i++)
{
memoryAddress[a][i] = memoryArray[a][i];
}
return memoryAddress;
}
}
cache class
publicclass Cache
{
int numberOfMisses, numberOfHits;
privateboolean [] validityArray =newboolean [32];
privateint [] indexArray =newint [32];
privateint [] tagArray =newint [32];
privateint [][] cacheblocksArray =newint [32][8];
publicdouble getMissRate()
{
return numberOfMisses / (numberOfMisses + numberOfHits);
}
publicint getIndex(int block)
{
return indexArray[block];
}
publicvoid setCacheTag(int block,int tag)
{
tagArray[block] = tag;
}
publicint getCacheTag(int block)
{
return tagArray[block];
}
publicvoid setBlockValidity(int block,boolean validity)
{
validityArray[block] = validity;
}
publicboolean getBlockValidity(int block)
{
return validityArray[block];
}
publicvoid fillCache(int address, Memory b)
{
b =new Memory();
b.getMemoryLocation(address);
// cacheblocksArray[getIndex()][];
}
publicint getIndexNumber(int address)
{
return address%32;
}
}
Message was edited by:
johnnysmith

