smlsim - #include <fstream> #include...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #include <fstream> #include <iostream> #include <string> #include <math.h> using namespace std; int main(int argc, char *argv){ ifstream inFile(argv[1]); int exitval = 0; int memory[100] = {0}; int accumulator; int instructionRegister; int operationCode; int operand; int instructionCounter; while (!inFile.eof()) { inFile >> instructionCounter; inFile >> instructionRegister; memory[instructionCounter] = instructionRegister; } inFile.close(); instructionCounter = 0; printf ("\n\n*------Welcome to Simpletron!--------------------------------------------------------------------------*\n\n\n"); printf ("--PROGRAM EXECUTION-------------------------------------------------------\n"); while (exitval == 0) { instructionRegister = memory[instructionCounter]; operationCode = instructionRegister / 100; operand = instructionRegister % 100; switch (operationCode) { case 10: do { cin >> memory[operand]; //READ } while ((memory[operand] < -9999) || (memory[operand] > 9999)); printf (" read: "); if ((memory[operand] < 0) && (memory[operand] > -10)) printf ("-000"); if ((memory[operand] <= -10) && (memory[operand] > -100)) printf ("-00"); if ((memory[operand] <= -100) && (memory[operand] > -1000)) printf ("-0"); if ((memory[operand] <= -1000) && (memory[operand] > -10000)) printf ("-"); if (memory[operand] < -9999) printf ("*** Simpletron executution abnormally terminated"); if ((memory[operand] >= 0) && (memory[operand] < 10)) printf ("+000"); if ((memory[operand] >=10) && (memory[operand] < 100)) printf ("+00"); if ((memory[operand] >=100) && (memory[operand] < 1000)) printf ("+0"); if ((memory[operand] >= 1000) && (memory[operand] < 10000)) printf ("+"); if (memory[operand] > 9999) printf ("*** Simpletron executution abnormally terminated"); printf ("%d\n", abs(memory[operand])); //printf (" read: %d\n", memory[operand]); ++instructionCounter; break; case 20: accumulator = memory[operand]; //LOAD printf (" load: "); if ((memory[operand] < 0) && (memory[operand] > -10)) printf ("-000"); if ((memory[operand] <= -10) && (memory[operand] > -100)) printf ("-00"); if ((memory[operand] <= -100) && (memory[operand] > -1000)) printf ("-0"); if ((memory[operand] <= -1000) && (memory[operand] > -10000)) printf ("-"); if (memory[operand] < -9999) printf ("*** Simpletrom execution terminated abnormally"); if ((memory[operand] >= 0) && (memory[operand] < 10)) printf ("+000"); if ((memory[operand] >=10) && (memory[operand] < 100)) printf ("+00"); if ((memory[operand] >=100) && (memory[operand] < 1000)) printf ("+0"); if ((memory[operand] >= 1000) && (memory[operand] < 10000)) printf ("+"); if (memory[operand] > 9999) printf ("*** Simpletrom execution terminated abnormally"); printf ("%d\n", abs(memory[operand])); //printf (" load: %d\n", memory[operand]); ++instructionCounter; //printf ("load: "); break; case 30: accumulator += memory[operand]; //ADD printf (" add: "); if ((accumulator < 0) && (accumulator > -10)) printf ("-000"); if ((accumulator <= -10) && (accumulator > -100)) printf ("-00");...
View Full Document

This note was uploaded on 09/29/2008 for the course CS 253 taught by Professor Monte during the Spring '08 term at Colorado State.

Page1 / 8

smlsim - #include <fstream> #include...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online