View Single Post
  #3  
Old 06-14-2013, 02:53 PM
r00t r00t is offline
Sarnak


Join Date: Jun 2013
Posts: 330
Default

[You must be logged in to view images. Log in or Register.]

Code:
#include <iostream>
#include <stdlib.h>
#include <string>

#include "VonEmu.h"

int main(int argc, char* argv[])
{
    std::string inputBuffer;
    VonEmu* von = new VonEmu();

    while (getline(std::cin, inputBuffer))  // read redirected input file line b
y line
        von->feedInput(atoi(inputBuffer.c_str()));  // add it to the emulated me
mory

    // use do-while to print out initial values
    do std::cout << *von << std::endl;
    while (von->runProgram());     // repeat forever until terminates

    delete von;
    return 0;
}
Code:
###############################################################*/
class VonEmu
{

    public:
        VonEmu();

        enum Opcode { Load = 1, Store, Add, Subtract, Branch, Stop };

        // overload << to cout the object's memory, PC, ACC, etc.
        friend std::ostream& operator<<(std::ostream &os, const VonEmu &v);

        bool feedInput(int input);
        bool runProgram(); // executes single next instruction pointed to by _pr
ogramCounter

    protected:
        int _accumulator;
        int _programCounter;

        int _memory[VONEMU_MAX_MEMORY];

        int _inputOffset;  // offset representing the current memory location to
 store data in
        bool _inputDataFlag; // true if storing data, false if storing to locati
ons

    private:
        bool _executeInstruction(int instructionOpcode, int instructionData);
};