Question
n this assignment you will write a program to simulate a fictional computer that we will call the Simplesim. As its name implies it is
n this assignment you will write a program to simulate a fictional computer that we will call the Simplesim. As its name implies it is a simple machine. All information in the Simplesim is handled in terms of words. A word is a signed four-digit decimal (base 10) number such as +3364, -1293, +0007, -0001, 0000, etc. The Simplesim is equipped with memory and five registers.
You will need to write three files for this assignment: IN C++ PLEASE!
-
sml.h - This header file must contain all the #define statements that define the Simplesim's instruction set. i.e., #define READ 11, #define WRITE 12, etc. The header file should have an appropriate set of header guards to prevent it from being included multiple times in the same source file.
-
simplesim.h - This header file should contain the class definition for a class called simplesim. This class definition should contain the private data members described below under 7. Simulating the Simplesim. It should also contain public declarations (i.e., prototypes) for the four member functions whose definitions are contained in simplesim.cpp (described below). The header file should have an appropriate set of header guards.
-
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 (, , etc.):
#include "sml.h" #include "simplesim.h"
This will ensure that the code that you write for your member functions will have access to the definition of the simplesim class and the #define statements that define the Simplesim instruction set.
-
Note that there is no mention here of a main() function for the program. That function will be provided to you in a separate file (described below under 8. Files I Give You). It will be linked together with your code for the simplesim class during the build process initiated by the make command.
The setup script will create the directory Assign4 under your csci241 directory. It will copy a makefile named makefile to the assignment directory.
Unlike the makefiles for the previous three assignments, this makefile has only a single executable target named simplesim. You can build the entire project for Assignment 4 simply by typing the command make.
The setup process will also copy a file named main.cpp to your assignment directory. This is a short driver program consisting of a main() function that does the following:
- Creates an object of the simplesim class.
- Calls load_program() for that object to read and load an SML program.
- If the call to load_program() returns true, it calls execute_program() for the object to execute the loaded SML program. Otherwise, it just skips to the next step.
- Calls dump() for the simplesim object to dump its registers and memory.
You will also receive a collection of SML programs. They include three SML programs that work (including the two example SML programs sum and max) and a collection of SML programs intended to abend.
Finally, you will also receive an executable file, simplesim.key. This is the solution to the assignment. You may use the SML programs above along with the solution (simplesim.key) to debug your program. The output of your program must look exactly like the output produced by simplesim.key. Your program will be tested in the following manner:
z123456@turing:~/csci241/Assign4$ ./simplesim.key < sum.sml > sum.key z123456@turing:~/csci241/Assign4$ ./simplesim < sum.sml > sum.out z123456@turing:~/csci241/Assign4$ diff sum.out sum.key
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