int main(int argc, const char *argv[]) { Simpletron s; s.go(); return 0; }
void SimpletronSimulator::loadTest6(Simpletron &program) //Compute exponentiation of one number to another numbers power { cout << "*** Simpletron Program Instructions ***" << endl; cout << " 00 ? +10007" << endl; program.store(0, 10007); cout << " 01 ? +10008" << endl; program.store(1, 10008); cout << " 02 ? +20007" << endl; program.store(2, 20007); cout << " 03 ? +35008" << endl; program.store(3, 35008); cout << " 04 ? +21009" << endl; program.store(4, 21009); cout << " 05 ? +11009" << endl; program.store(5, 11009); cout << " 06 ? +43000" << endl; program.store(6, 43000); cout << " 07 ? +00000" << endl; program.store(7, 00000); cout << " 08 ? +00000" << endl; program.store(8, 00000); cout << " 09 ? +00000" << endl; program.store(9, 00000); }
void SimpletronSimulator::loadTest5(Simpletron &program) //Compute remainder of 2 numbers { cout << "*** Simpletron Program Instructions ***" << endl; cout << " 00 ? +10007" << endl; program.store(0, 10007); cout << " 01 ? +10008" << endl; program.store(1, 10008); cout << " 02 ? +20007" << endl; program.store(2, 20007); cout << " 03 ? +34008" << endl; program.store(3, 34008); cout << " 04 ? +21009" << endl; program.store(4, 21009); cout << " 05 ? +11009" << endl; program.store(5, 11009); cout << " 06 ? +43000" << endl; program.store(6, 43000); cout << " 07 ? +00000" << endl; program.store(7, 00000); cout << " 08 ? +00000" << endl; program.store(8, 0000); cout << " 09 ? +00000" << endl; program.store(9, 00000); }
// Main method to begin inputing and executing code. int main (int argc, char *argv[]) { Simpletron comp = Simpletron(); comp.enterSML(); comp.execute(); system("Pause"); }
// Main function, will cycle through int main() { Simpletron myComputer; // Creation of Simpletron Computer Object. printMessage(); // Print introduction message. myComputer.loadMemory(); // Load memory from file. myComputer.execute(); // Execute file commands found within myComputer memory. return 0; }
/************************************************************************* * Date last modified: July 16th, 2013 * Description: Loads a simple machine language program from file * Input parameters: File to output to, program to load into * Returns: * Precondition: File is open * Postcondition: Memory is updated with program from file *************************************************************************/ void SimpletronSimulator::loadProgram(ifstream &file, Simpletron &program) { int i = 0, tempNum = 0; while(file.good()) { file >> tempNum; program.store(i, tempNum); } }
int main() { Simpletron cpu; cpu.setProgramFromStdin(); std::cout << "Finished loading program. Beginning execution." << std::endl; cpu.run(); }
void SimpletronSimulator::loadTest8(Simpletron &program) //Determines if there is a remainder between two numbers (Test branch if 0) { cout << "*** Simpletron Program Instructions ***" << endl; cout << " 00 ? +10009" << endl; program.store(0, 10009); cout << " 01 ? +10010" << endl; program.store(1, 10010); cout << " 02 ? +20009" << endl; program.store(2, 20009); cout << " 03 ? +34010" << endl; program.store(3, 34010); cout << " 04 ? +42007" << endl; program.store(4, 42007); cout << " 05 ? +11012" << endl; program.store(5, 11012); cout << " 06 ? +43000" << endl; program.store(6, 43000); cout << " 07 ? +11011" << endl; program.store(7, 11011); cout << " 08 ? +43000" << endl; program.store(8, 43000); cout << " 09 ? +00000" << endl; program.store(9, 00000); cout << " 10 ? +00000" << endl; program.store(10, 0000); cout << " 11 ? +00000" << endl; program.store(11, 00000); cout << " 12 ? +00001" << endl; program.store(12, 00001); cout << "Note: Program returns 1 if there is a remainder and 0 if no remainder" << endl; }
void SimpletronSimulator::loadTest7(Simpletron &program) //Determines which of two numbers is largest { cout << "*** Simpletron Program Instructions ***" << endl; cout << " 00 ? +10009" << endl; program.store(0, 10009); cout << " 01 ? +10010" << endl; program.store(1, 10010); cout << " 02 ? +20009" << endl; program.store(2, 20009); cout << " 03 ? +31010" << endl; program.store(3, 31010); cout << " 04 ? +41007" << endl; program.store(4, 41007); cout << " 05 ? +11009" << endl; program.store(5, 11009); cout << " 06 ? +43000" << endl; program.store(6, 43000); cout << " 07 ? +11010" << endl; program.store(7, 11010); cout << " 08 ? +43000" << endl; program.store(8, 43000); cout << "09 ? +00000" << endl; program.store(9, 00000); cout << " 10 ? +00000" << endl; program.store(9, 00000); }
/************************************************************************* * Date last modified: July 9th, 2013 * Description: Runs program that has already been loaded into memory * Input parameters: * Returns: * Precondition: Valid program exists in memory * Postcondition: Valid result is printed to console *************************************************************************/ void SimpletronSimulator::runProgram(Simpletron &program) { setAccumulator(0); setInstructionCounter(0); instructionRegister = program.memory[instructionCounter]; operationCode = program.getInstruction(instructionRegister); while(instructionCounter != -9999 && operationCode != 43) { operand = program.getLocation(instructionRegister); switch(operationCode) { case 10: // Read word from terminal into memory location program.read(operand); break; case 11: // Write a word from memory location to console program.write(operand); cout << endl; break; case 20: // Load a word from memory location into accumulator accumulator = program.load(operand); break; case 21: //Store a word from accumulator into memory location program.store(operand, accumulator); break; case 30: // Add a word from memory location to word in accumulator accumulator += program.memory[operand]; break; case 31: // Subtract a word from memory location from word in accumulator accumulator -= program.memory[operand]; break; case 32: // Divide a word from memory location into word in accumulator if(program.memory[operand] != 0) { accumulator /= program.memory[operand]; } else { cout << "***Fatal Error: Attempt to divide by zero***" << endl; cout << "***Simpletron execution abnormally terminated***" << endl; instructionCounter = -9999; } break; case 33: // Multiply word from memory location with word in accumulator accumulator *= program.memory[operand]; break; case 34: // Mod word from memory location into word in accumulator accumulator %= program.memory[operand]; break; case 35: // Calculate accumulator to the power of word in memory location accumulator = (int)pow(accumulator, program.memory[operand]); break; case 40: // Branch to a specific location in memory instructionCounter = operand-1; break; case 41: // If accumulator is negative branch to memory location if(accumulator < 0) { instructionCounter = operand-1; } break; case 42: // If accumulator is zero branch to memory location if(accumulator == 0) { instructionCounter = operand-1; } break; } if(instructionCounter != -9999) { instructionCounter++; instructionRegister = program.memory[instructionCounter]; operationCode = program.getInstruction(instructionRegister); } } if(instructionCounter != -9999) { cout << "***Simpletron Execution Terminated***" << endl; } }