public static byte[] main_Mem = new byte[2048];
public static SlotNode[] cache = new SlotNode[8];
Doesn’t this create instances of the objects? Why would I be getting a NPE?
//initialize main memory
for (int i = 0; i<main_Mem.length; i++) {
main_Mem[i] = (byte) (0xFF & i);
System.out.printf("%X", 0xFF & i);
System.out.print(" " + i);
System.out.println(" ");
}
//initialize cache slots to 0
for (int i = 0; i<cache.length; i++) {
cache[i].setValidBit(0);
cache[i].setTag(0);
cache[i].setData(0);
cache[i].setDirty(0);
}
You need to init the SlotNode, such as this:
By doing this:
you just initialize the array of 8
SlotNodeinstances – you need to initialize each of them separately.