Question
fix program in c++ please simplesim.cpp - This source file will contain function definitions for the following four member functions of the simplesim class: simplesim.cpp
fix program in c++ please
simplesim.cpp - This source file will contain function definitions for the following four member functions of the simplesim class:
simplesim.cpp - This source file will contain function definitions for the following four member functions of the simplesim class:
-
simplesim::simplesim()
This "default constructor" takes no arguments and has no return value. Its job is to perform the initialization process for a simplesim object described under 7.1. Initialize Simplesim.
-
bool simplesim::load_program()
This member function reads an SML program from standard input and attempts to load it into the Simplesim's memory, as described under 7.2. Load SML Program. It takes no arguments and returns a Boolean value indicating whether or not the program was successfully loaded (true if so, false if the load process abnormally terminated).
-
void simplesim::execute_program()
This member function executes an SML program in the Simplesim's memory, as described under 7.3. Execute SML Program. It takes no arguments and returns nothing.
-
void simplesim::dump() const
This member function dumps the contents of the Simplesim's registers and memory, as described under 7.4. Dump Simplesim. It takes no arguments and returns nothing. Since this method does not modify any any of the data of the simplesim object that calls it, it is declared to be const.
Place the following two #include statements at the top of this file, following any other required #include statements that you have coded (
code skeleton:
#include
#include "sml.h" #include "simplesim.h"
using namespace std;
simplesim::simplesim() { for (int i = 0; i < 100; i++) memory[i] = 7777; }
bool simplesim::load_program() { int count = 0; int instruction;
while (cin >> instruction && instruction != -99999) { if (not_valid_word(instruction)) { cout << "*** ABEND: pgm load: invalid word *** "; return false; }
if (count >= 100) { // print error and return false. }
// copy instruction into memory and increment count. }
return true; }
bool simplesim::not_valid_word(int word) const { return (word < -9999 || word > 9999); }
void simplesim::execute_program() { bool done = false; instruction_counter = 0;
while (!done) { // instruction fetch // Test instruction counter
instruction_register = memory[instruction_counter];
operation_code = instruction_register / 100; operand = instruction_register % 100; // instruction execute switch (operation_code) { case READ: break;
case WRITE: break; // More cases
case HALT: cout << "*** Simplesim execution terminated *** "; done = true; break; default: // Print error and return }
if (/*operation_code is not branching*/ && !done) instruction_counter++; } }
void simplesim::dump() const { // Print the registers. cout << "REGISTERS: ";
cout << "accumulator: " << accumulator << endl; cout << "instruction_counter: " << instruction_counter << endl; cout << "instruction_register: " << instruction_register << endl; cout << "operation_code: " << operation_code << endl; cout << "operand: " << operand << endl;
// Print memory. cout << " MEMORY: ";
for (int i = 0; i < 100; i++) cout << memory[i] << endl; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started