그래서 나는 다음과 같습니다 내 기억 클래스가 있습니다널에 refrence 예외 처리되지 않은이
namespace GeminiCore
{
public class Memory
{
public static int[] memory = new int[256];
public string nextInstruction;
public static int cacheSize = 8;
public CPU myCPU;
public struct frame
{
public bool dirtyBit;
public int isEmpty;
public int value;
public int tag;
public frame(int cacheSize)
{
dirtyBit = false;
isEmpty = 1;
value = 0;
tag = 0;
}
}
public int solveMemory(int value, int instr, frame[] myCache)
{
Console.WriteLine("I reached the solveMemory!!!");
int block = value % cacheSize;
if(instr == 127 || instr == 125 || instr == 124 || instr == 123
|| instr == 122 || instr == 121|| instr == 120)
{
Console.WriteLine("I reached the read section!!!");
if(myCache[block].isEmpty == 0) //Read hit
if(myCache[block].tag == value)
return myCache[block].value;
else
{
myCache[block].value = memory[value]; //Read Miss
myCache[block].tag = value;
myCache[block].isEmpty = 0;
Console.WriteLine("Read Miss --- The Cache is as follows: block = " + block + " the value at this block is: " + myCache[block].value + " the tag at this block is: " + myCache[block].tag);
return myCache[block].value;
}
}
else
{
Console.WriteLine("I reached the write section!!!");
if (myCache[block].isEmpty == 1) //Write Miss
{
Console.WriteLine("Write Miss --- The Cache is as follows: block = " + block + " the value at this block is: " + myCache[block].value + " the tag at this block is: " + myCache[block].tag);
memory[value] = myCPU.ACC;
}
else
{
if (myCache[block].dirtyBit == false)
{
if (myCache[block].tag != value)
{
myCache[block].value = myCPU.ACC; //Write Hit
myCache[block].dirtyBit = true;
myCache[block].tag = value;
Console.WriteLine("Write Hit --- The Cache is as follows: block = " + block + " the value at this block is: " + myCache[block].value + " the tag at this block is: " + myCache[block].tag);
}
}
else
{
memory[myCache[block].tag] = myCache[block].value;
myCache[block].value = myCPU.ACC;
myCache[block].tag = value;
myCache[block].dirtyBit = false;
Console.WriteLine("Write Hit --- The Cache is as follows: block = " + block + " the value at this block is: " + myCache[block].value + " the tag at this block is: " + myCache[block].tag);
}
}
}
return value;
}
}
}
을 다음 내 CPU 클래스가 있고, 난 그냥 작은 조각을 게시 할 예정입니다 여기서 오류가 발생의 : 내가 어셈블리 코드에 소요 한 후 이진 그것을 변환 내 테스트를 실행할 때 코드를 실행 그래서 여기
public Memory myMemory;
public static Memory.frame[] myCache = new Memory.frame[Memory.cacheSize];
public void doInstruction()
{
var instr = (finalCodes[i] >> 9) & 127; //Parses op code to find instruction
var immed = (finalCodes[i] >> 8) & 1; //Parses op code to find immediate value
var value = (finalCodes[i] & 255); //Parse op code to find value
foreach (Memory.frame x in myCache)
{
Console.WriteLine("Dirtybit: " + x.dirtyBit + " isEmpty: " + x.isEmpty + " tag: " + x.tag + " value: " + x.value);
}
switch (instr)
{
case (127): //LDA instruction
if (immed == 1)
ACC = value;
else if (immed == 0)
//ACC = Memory.memory[value];
ACC = myMemory.solveMemory(value, instr, myCache);
break;
case (126): //STA instruction
if (immed == 0)
{
Console.WriteLine("The value is: " + value + " The instruction is: " + instr);
foreach (Memory.frame x in myCache)
{
Console.WriteLine("Dirtybit: " + x.dirtyBit + " isEmpty: " + x.isEmpty + " tag: " + x.tag + " value: " + x.value);
}
//Memory.memory[value] = ACC;
myMemory.solveMemory(value, instr, myCache);
}
내 문제는, 내가 도착하면 두 번째 명령 "sta"라인에 가야합니다 :
그런 다음 해당 포인트에 도달하면 널 참조 예외가 발생합니다. 보시다시피, 나는 명령 행을 출력하여 어디로 가는지 보려고한다. 그 라인 바로 전에 myCache의 내용을 출력합니다. 그것은, 그러나 solveMemory 기능에없는 경우에도 첫 번째를 디버그 문 중 하나를 도달하지 않습니다 말한다 :
Console.WriteLine("I reached the solveMemory!!!");
내가 그것을보고 있었어요이 오류의 원인이되고 정말로 확실하지 않다 꽤 많은 시간. 바라건대 당신 중 하나가 정확히 내가 엉망이 어디 있는지 찾을 수있을 것입니다. 시간 내 주셔서 감사합니다.
는 그럼 난 null 참조 예외가 나는 아마도 내가 뭔가를 누락 내 코드 – VakarianWrex
에 받고 있어요 왜, 난 그냥 알아낼 수 없습니다 무엇인지, 하지만 실제로 myMemory에 할당하는 위치는 어디입니까? –
와우, 나는 그것을 믿을 수 없다. 그냥 메모리 myMemory = 새로운 메모리(); – VakarianWrex