/* ************************************************************ *新建一个内存模块,并且将这内存模块添加到尾部 ************************************************************ */ item_Mem* ModMemory::newNameMem(const char* inName,size_t in_Length) { item_Mem* mMem = newMem(in_Length); //设置名字 mMem->name = strdup(inName); return mMem; }
/* * Creates memeory for the program to run and gets the instruction code along * with the registers. */ void build_and_execute_um(FILE* program){ memorySegments = newMem(); instantiateMem(memorySegments, INITIAL_SET_SIZE); initializeRegisters(registers, numRegisters); mapProgram(program); programCounter = 0; numInstructions = instructionLength(); //programPointer = getInstructions(memorySegments); while(programCounter < numInstructions){ UM_Word instruction = getInstruction(programCounter); Instruction instr = parseInstruction(instruction); execute_instruction(instr); if(instr.op == HALT) break; } freeMem(memorySegments); }
/* ************************************************************ *新建一个内存模块,并且将这内存模块添加到尾部 ************************************************************ */ item_Mem* ModMemory::newMem(void* inAddr,size_t in_Length) { item_Mem* mMem = newMem(in_Length); memcpy(mMem->Addr,inAddr,in_Length); return mMem; }