void execute() { //printInstructionTable(); int pc = 0; char opcode[OPCODE_SIZE]; char operand[OPERAND_SIZE]; while(strcmp(opcode, "halt")){ fetchInstruction(pc, opcode, operand); // execution of current instruction if(strcmp(opcode, "nop") == 0){pc = nop(pc);} else if(strcmp(opcode, "add") == 0){pc = add(pc);} else if(strcmp(opcode, "sub") == 0){pc = sub(pc);} else if(strcmp(opcode, "mul") == 0){pc = mul(pc);} else if(strcmp(opcode, "divide") == 0){pc = divide(pc);} else if(strcmp(opcode, "get") == 0){pc = get(pc, operand);} else if(strcmp(opcode, "put") == 0){pc = put(pc, operand);} else if(strcmp(opcode, "push") == 0){pc = push(pc, operand);} else if(strcmp(opcode, "pop") == 0){pc = pop(pc, operand);} else if(strcmp(opcode, "not") == 0){pc = not(pc);} else if(strcmp(opcode, "and") == 0){pc = and(pc);} else if(strcmp(opcode, "or") == 0){pc = or(pc);} else if(strcmp(opcode, "testeq") == 0){pc = testeq(pc);} else if(strcmp(opcode, "testne") == 0){pc = testne(pc);} else if(strcmp(opcode, "testlt") == 0){pc = testlt(pc);} else if(strcmp(opcode, "testle") == 0){pc = testle(pc);} else if(strcmp(opcode, "testgt") == 0){pc = testgt(pc);} else if(strcmp(opcode, "testge") == 0){pc = testge(pc);} else if(strcmp(opcode, "jump") == 0){pc = jump(pc, operand);} else if(strcmp(opcode, "jf") == 0){pc = jf(pc, operand);} } }
void runProgram(){ int pc = 0; char lastOp[OPCODE_SIZE]; int haltHit = 0; while(!haltHit){ if(strcmp(fetchOpcode(pc), "nop") == 0){ pc = nop(pc); } if(strcmp(fetchOpcode(pc), "add") == 0){ pc = add(pc); } if(strcmp(fetchOpcode(pc), "sub") == 0){ pc = sub(pc); } if(strcmp(fetchOpcode(pc), "mult") == 0){ pc = mult(pc); } if(strcmp(fetchOpcode(pc), "div") == 0){ pc = divide(pc); } if(strcmp(fetchOpcode(pc), "get") == 0){ pc = get(pc); } if(strcmp(fetchOpcode(pc), "put") == 0){ pc = put(pc); } if(strcmp(fetchOpcode(pc), "push") == 0){ pc = push(pc); } if(strcmp(fetchOpcode(pc), "pop") == 0){ pc = pop(pc); } if(strcmp(fetchOpcode(pc), "not") == 0){ pc = not(pc); } if(strcmp(fetchOpcode(pc), "and") == 0){ pc = and(pc); } if(strcmp(fetchOpcode(pc), "or") == 0){ pc = or(pc); } if(strcmp(fetchOpcode(pc), "tsteq") == 0){ pc = testeq(pc); } if(strcmp(fetchOpcode(pc), "tstne") == 0){ pc = testne(pc); } if(strcmp(fetchOpcode(pc), "tstlt") == 0){ pc = testlt(pc); } if(strcmp(fetchOpcode(pc), "tstle") == 0){ pc = testle(pc); } if(strcmp(fetchOpcode(pc), "tstgt") == 0){ pc = testgt(pc); } if(strcmp(fetchOpcode(pc), "tstge") == 0){ pc = testge(pc); } if(strcmp(fetchOpcode(pc), "j") == 0){ pc = jump(pc); } if(strcmp(fetchOpcode(pc), "jf") == 0){ pc = jf(pc); } if(strcmp(fetchOpcode(pc), "halt") == 0){ haltHit = 1; pc = halt(pc); } } }