/// <summary> /// Define the main memory block according to the preferences. /// </summary> /// <param name="preferences"></param> /// <param name="len"></param> /// <returns></returns> public uint DefineMemory(SimulatorPreferences preferences, int len) { //extract start of memory address from preferences uint address = preferences.MemoryStart; uint stackPointer; uint programSizeBytes = (uint)((((len * 4) + 1023) / 1024) * 1024); uint stackSizeBytes = preferences.StackAreaSize * 1024; uint heapSizeBytes = preferences.HeapAreaSize * 1024; if (preferences.StackGrowsDown) { stackPointer = (uint)(address + programSizeBytes + heapSizeBytes + stackSizeBytes); heapPointer = (uint)(address + programSizeBytes); } else { stackPointer = (uint)(address + programSizeBytes); heapPointer = (uint)(address + programSizeBytes + heapSizeBytes + stackSizeBytes); } //compute size of main memory in words uint sizeWords = (uint)((programSizeBytes + stackSizeBytes + heapSizeBytes) / 4); //init the main memory block mMemoryBlock = new MemoryBlock(address, sizeWords, preferences); mMemoryBlock.HeapStart = heapPointer; mMemoryBlock.StackStart = stackPointer; if (preferences.StackGrowsDown) { mMemoryBlock.HeapEnd = heapPointer + heapSizeBytes; mMemoryBlock.StackEnd = stackPointer - stackSizeBytes; } else { mMemoryBlock.HeapEnd = heapPointer - heapSizeBytes; mMemoryBlock.StackEnd = stackPointer + stackSizeBytes; } return(stackPointer); }//DefineMemory
public MainMemory(SimulatorPreferences simulatorPreferences) : this() { mSimulatorPreferences = simulatorPreferences; }