int main(int argc, char* argv[]) { (void) argc; (void) argv; Mem* mem; NEW(mem); instantiateMem(mem, MEM_SEG_LEN); UM_Word index = mapSegment(mem, 10); printf("mapped index: %u\n", index); verifyMapped(mem->mappedIDs, mem->unmappedIDs); UM_Word value = 20; segmentedStore(mem, 0, 9, value); if(segmentedLoad(mem, 0, 9) != value) { fprintf(stderr, "incorrect load and store"); exit(1); } else { printf("value: %u\n", segmentedLoad(mem, 0, 9)); printf("Woohoo! Correct seg store and load!\n"); } unmapSegment(mem, index); verifyMapped(mem->mappedIDs, mem->unmappedIDs); freeMem(mem); return 0; }
/* * 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); }
int main(int argc, char* argv[]) { (void) argc; (void) argv; Mem* mem; NEW(mem); instantiateMem(mem, MEM_SEG_LEN); printf("Verifying after instantiate:\n"); verifyMapped(mem->mappedIDs, mem->unmappedIDs); mapSegment(mem, 0, 10); verifyMapped(mem->mappedIDs, mem->unmappedIDs); UM_Word value = 0; segmentedStore(mem, 0, 9, value); if(segmentedLoad(mem, 0, 9) != value) { fprintf(stderr, "incorrect load and store"); exit(1); } else { printf("value at memseg: %u\n", segmentedLoad(mem, 0, 9)); printf("Woohoo! Correct seg store and load!\n"); } printf("resizing\n"); mapSegment(mem, 11, 1); printf("verifying index 1 mapping\n"); verifyMapped(mem->mappedIDs, mem->unmappedIDs); unmapSegment(mem, 0); printf("verifying index 0 unmapping\n"); verifyMapped(mem->mappedIDs, mem->unmappedIDs); unmapSegment(mem, 11); printf("verifying index 1 unmapping\n"); verifyMapped(mem->mappedIDs, mem->unmappedIDs); freeMem(mem); return 0; }