main.cpp - #include#include#include#include#include#include...

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

View Full Document Right Arrow Icon
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <fstream> #include <sstream> using namespace std; class Accumulator { private: int reg = 0; public: void load(int val) { reg = val; } int getReg() { return reg; } void add(int val) { reg += val; } void sub(int val) { reg-=val; } }; // Globals vector<string> v; int accumulator = -1; int instructionCounter = -1; string instructionRegister = "00000"; int opCode = -1; int operand = -1; // Forward declaration functions void printMemory(vector<string>& v); void read(int location); int main(int argc, char* argv[]) { enum OPCODES { READ=10, WRITE=11, LOAD=20, STORE=21, ADD=30, SUBTRACT=31, DIVIDE=32, MULTIPLY=33, BRANCH=40, BRANCHNEG=41, BRANCHZERO=42, HALT=43, MEMDUMP=50, BREAK=51, CONTINUE=52 }; Accumulator acc; v.resize(100); for_each(begin(v), end(v), [] (string & s) {s="00000";}); if(argc == 1) { cout << "Enter values. Enter -9999 to quit" << endl; string input = ""; int i=0; cout << i << " ? "; while( cin>>input ) {
Image of page 1

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

View Full Document Right Arrow Icon
if(input == "-9999") break; v[i] = input; i++; cout << i << " ? "; }; } else { int s =0; ifstream i(argv[1]); string line; while(getline(i, line)) { if(line[0] == '+') line[0] = '0'; v[s] = line; s++; } } bool end = false; instructionCounter = 0; while(!end) {
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern