Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Coded in c++. Your program will take as input an SML program followed by any input for that SML program. The input file will start

Coded in c++. Your program will take as input an SML program followed by any input for that SML program.

The input file will start with the SML program, one instruction per line. Following the last line of the SML program will be the number -99999, which is not part of the SML program. If the SML program expects any input (i.e., if it has any READ instructions) then input for the SML program, one input value per line, immediately follows the -99999 line. For example, below is the input file for the first program from the previous section. It adds -5 and 15.

0107 0108 1207 2108 1109 0209 3400 0000 0000 0000 -99999 -5 15 

Note that each line of the input file, other than -99999 which is used to denote the end of program and not intended to be placed into the Simplesim's memory, fits into a single word. Note also that not all SML programs require input (those that do not have READ instructions). In that case there would be no data after the -99999 line.

All input files to your program have -99999 after the last SML instruction. For those SML programs that do not require input, (those that do not have READ instructions), -99999 is simply the last line of the input file.

5. Output

Each time a READ instruction is executed your program must print the value that was read. For example, the two values read in the program from the previous section are -5 and 15. As each value is read, your program should print output that looks exactly like this.

READ: -0005 READ: +0015 

For each WRITE instruction your program must print the value of the word in that memory location. For example, from the program in the previous section, the sum 10 is printed exactly like this.

+0010 

When the HALT statement is executed, your program should print the following line:

*** Simplesim execution terminated *** 

At the end of any execution your program should dump the entire contents of the Simplesim. This means dumping the contents of all five registers and all 100 words of the Simplesim's memory.

Assuming that the name of your program is simplesim and the name of the SML program file above is sum.sml, then the output of your program must look exactly like this:

z123456@turing:~/csci241/Assign4$ ./simplesim < sum.sml READ: -0005 READ: +0015 +0010 *** Simplesim execution terminated *** 

One of the first things that your program will do is read the SML program into the Simplesim's memory. This is called loading the program. There are a couple of things that could go wrong when loading the program; the program may be too large for the Simplesim's 100-word memory or a line of the input file may not fit into a word (i.e., it may be greater than 9999 or less than -9999). In these situations your program should print an error message, dump the contents of the machine, and terminate. It should not start to run the SML program.

If there was a successful SML program load, your program should start to execute the SML program. SML programs, like any other programs, may perform an illegal operation and terminate abnormally (abend). There are a number of conditions that may cause an SML program to abend, in which case processing stops immediately An example of this is an attempt to divide by 0. In that case, the Simplesim should print an appropriate abend message, stop execution, and dump the contents of the machine. Every execution of your program (normal termination of the SML program or SML program abend) ends with a dump of the Simplesim.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions

Question

Define shareholder wealth. Explain how it is measured.

Answered: 1 week ago

Question

Shelly Cashman PowerPoint 2019 | Module 1: SAM Project 1a

Answered: 1 week ago

Question

Discuss the history of human resource management (HRM).

Answered: 1 week ago