Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This assignment is the first in a sequence of three. It is not strictly necessary to complete this one in order to do the other
This assignment is the first in a sequence of three. It is not strictly necessary to complete this one in order to do the other two, but the understanding you gain in completing this assignment will make writing the third assignment (a major project much easier. You will need to complete the second in the sequence in order to do the third. Ve start by peeling open" a computer, look at its internal structure, and introducing machine language (assembler level programming. Your assignment is to write a program that simulates a computer, one that is capable of executing machine language programs. 1. Initial Setup 1. Log in to Unix. 2. Run the setup script for Assignment 4 by typing: 2. Description of the Simplesim Computer this assignment you will write a program to simulate a fictional computer that we will call the Simplesim. As its name imples 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. The Simplesim has a 100 word memory and these words are referenced by their location numbers 00.01.... 99. Each word in the Simplesim's memory Calways a single signed four-digit decimal number) may be interpreted as an instruction to be executed, a data value, or may be uninitialized. The firsc register is the accumulator, which is just large enough to hold a single word. Words from memory must be placed into the accumulator in order to perform arithmetic on them or test their values. All arithmetic and branching is done using the accumulator The second register is the instruction counter, which is just large enough to hold a memory locations (a two digit number 00, 01.... 99). The instruction counter is used to hold the memory location of the next instruction to be executed. The third register is the instruction register, which, like the accumulator, is just large enough to hold a single word. The instruction register is used to hold a copy of the instruction (a word that was pulled out of memory that is currently being executed. The fourth and fifth registers are the operation code and operand, respectively. Each one is just large enough to hold hall of a word a two digit decimal number. The operation code and operand registers are used to split the instruction register in hall with the leftmost digits and sign of the instruction register going into the operation code and the rightmost digits gaing into the operand. For example, if the instruction register had +1009, the operation code would have +10 and the operand would have 09. Likewise, if the instruction register had 1201, the operation code would have 12 and the operand would have 01: 3. The Simplesim Machine Language (SML) ach instruction written in the Simplesim Machine Language (SML) occupies one word of the Simplesim's memory and hence instructions are signed four digit decimal numbers). The two leftmost digits of each SML instruction are the operation code lopcode), which specifies the operation to be performed. The two rightmost digits of an SML instruction are the operand, which is the memory location containing the word to which the operation applies. The complete set of SML instructions is described in the able that follows. Operation Code Meaning Input/Output Operations: =detina READ 11 Read a word into a specilic memory location da? DA MRITE 12 Print a word from a specific memory location Sidre/ Load Operations #define SCORE 21 Store the word in the accumulator into a specific memory location Edetina LOAD 22 Load a word from a specific memory location into the accumulator Arithmetic Operations se?ine ADD 22 Add a word in a specific memory location to the word in the accumulator (leave result in accumulator). Edeline SL3ZPACT 32 Subtract a word in a specific memory location from the word in the accumulator (leave result in accumulator), define BOLESSLY 33 Multiply a word in a specific memory location by the word in the accumulator leave result in accumulator #6. DIVIDE 34 Divide a word in a specific memory location into the word in the accumulator leave result in accumulator Transler of Control Operations #define BRANCH 41 Branch to a specific memory location datinA BRANCH ZERO 42 Branch to a specific memory location it the accumulator is zero. #define BRANCANE 43 Branch to a specific memory location if the accumulator is negative. 802.ne SALT 44 Hall, i.e, the program has completed its task (Read A Ve illustrate how the simplesim executes SML programs (using the instructions from the table above) with the use of two example SML programs. Consider the following SML program which reads two numbers and computes and prints their sum. Memory Location Word Instruction +1107 01 +1109 (Read B) 02 2207 (Load A) +3108 (Add D) 04 +2109 (Score) 05 +1209 (Write +4400 (Halt) 07 +0000 (Variable 08 +0000 (Variable 09 +0000 (Result C) xecution always begins al memory location Co. The word at memory location 00 +1107) is read and interpreted as an instruction. The leftmost two digits of the word (11) represent the instruction and the rightmost two digits (07) represent the instruction's operand. The first instruction is a SEAD operation. This reads a single word from the input file (explained in Section 4) and stores it in the memory location defined by the operand, in this case memory location 07. READ and B.ITE instructions always perate on memory locations. This completes the execution of the first instruction Processing continues by executing the next instruction found a memory location 01. The next instruction [+110B) reads a second word from the input file and stores it in memory location 08. The next instruction (+2207) is a LOAD operation with operand 07. It takes the word found at memory location 07 (the operand) and places it into the accumulator (recall that the accumulator is one of the five registers described in Section 1). A LOAD and Store operations move data in and out of the accumulator. the next instruction (3106) is an ADD instruction with operand 02. AR SML arithmetic instructions are performed using the word in the accumulator and the word identified by the operand and the result is always left in the accumulator. This instruction takes the word stored in memory location of the operand) adds to the value in the accumulator, and leaves the sum in the accumulator The next instruction (+2109) is a SCORE instruction which, like all STORE instructions, takes the word in the accumulator (the sum of the two inpul values and stores it in the memory location identified by the instruction's operand, in this case memory location 09. Then +1209, a TIRLITE instruction, prints output is explained in Section 5) the word found in memory location 09, which again is the sum of the lo input values. Finally instruction +4400, the HALS instruction, is executed which simply terminales The next instruction (+2109) is a STORE instruction which, like all stora instructions, Lakes the word in the accumulator (the sum of the two input values and stores it in the memory location identified by the instruction's operand, in this case memory location 09. Then +1209, a ELITE instruction, prints (output is explained in Section 5) the word found in memory location 09, which again the sum of the two input values. Finally instruction +4400, the HALT instruction, is executed which simply terminates the SML program (operand 00 is ignored for this instruction) Note that a single word in memory can be used to store a single instruction that is to be executed or a single variable that should never be interpreted as an instruction. None of the memory locations after the HD instruction (memory locations 07-09) were executed, however, they were important in the computation. Those words were used to store the program's variables and temporary results. All SML programs will partition" the Simplesim's memory in this way. The first words of memary Calways starting at memary location 00) are the instructions of the program and following that after the SALI instruction, is the data" part of the progtam. The intention, of course, is that only the "instructions of the program are to be executed, ie, each word interpreted as an SML instruction Now consider this second SML program that reads two numbers and prints the larger of the two Memory Location Word Instruction +1109 01 1110 (Read D) +2209 (Load A +3210 (Subtract 04 +4307 (Branch negative to 07) OS 1209 (Write A) +4400 (Halt) +1210 (Write B) 08 (Halt) 09 (Variable A) +0000 (Variable 00 (Read A) +4400 10 The first two instructions (+1109 and +1110) read two values and store them in memory locations 09 and 10, respectively. -2209 places the word al memory location 09 (the first input value) into the accumulator. +3210, SUSTRACS Instruction takes the word al memory location 10 (the second input value), subtracts it from the accumulator, and leaves the result in the accumulator +4307 (BRANCENEC) is a conditional branch instruction, much like an "il" statement in Ch. All conditional branch instructions are based on the accumulator. The Ras instruction, which als like a gato", is the only branch instruction that ignore the accumulator, it is simply an unconditional branch. If the value in the accumulator is negative, which in this case means the second input value was the largest, then the next instruction that gets executed is the one al memory location 07 (the operand if the value in the accumulator is or greater meaning the liest input value was greater than or equal to the second, then execution continues with the next statement, i.e., no branching. If the branch was taken then the value at memory location 10 (the second input value is printed and the program terminates. Otherwise the value at memory location 09 (the first input value) Sprinted and the program terminales Note how the SML program is written. It partitions the Simplesim's memory into two distinct parts, the program" (locations 00 OB) and the data" (locations 09-10). This SML program, unlike the first has two HALS instructions. This is okay, only one of them will be executed. The point is that BALI instructions are used to prevent the execution of the program from wandering into the data portion of the program. 4. Input 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 (ie, 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. 1207 110 2103 -99999 Note that each line of the input me, other than 99999 which is used to denate the end of program and not intended to be placed into the Simplesimi'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 ine. All input files to your program have 99999 alter 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 WISZ 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. When the HALE Statement is executed, your program should print the following line *** Simple in Gaution ninated -- 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 aimpierim and the name of the SML program ie above is aam.nl, then the output of your programm must look exactly like this. =123456 ving:-/0201243/Aasion 4 / omplain aan SEAD: -0003 READ: 0015 - Simplesmention Caminated . -0010 REGISTESS: acownslator: instruction_counter instruction_regiates: pertson_code: operand: -4400 44 00 SEMORY 0-1107 -1108 -2207 3303 -2103 -1205 -4400-2005 +0013-0010 10 Find a 30 -7777-7777 +7717 +1777 - 1977 -7777-777777777777 +1777 40 -7777-7777-7777 +7777-7777-7777-777777777777-7777 50 -7777-777777777777-7777-7777-7777777777777777 60 -7777-77777777 +7777-7777-7777-7777777777777777 70 -77777777777777777-7777-7777-77777777777777777 80 -1777-77777777-7777 - 1777-7777-777777777777 +1777 90 -1771-77777777777777777 +7777-7777-7777777777777777-7777 =12345 Etag:-/ee1241/Asn4 One of the first things that your programs will do is read the SML pragrarn 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 lie, 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 SMIL program laad, 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 Io abend, in which case processing slops immediately An example of this is an attempt to divide by O. In that case, the Simplesim should print an appropriate abend message stop execution and dump the contents of the machine. [very execution of your program normal termination of the SML program or SML program abend) ends with a dump of the Simplesim. A summary of the possible abend conditions (program load and execution errors) with their error messages appear in the following table Note that all error messages must appear exactly as they appear in the table. Condition Error Message Description Program Load Errors: Program too big - ABEND: Pon load: pom teo lage *** The program is too big more than 100 words) to fit into memory Invalid word *** ABEND: Pon load: Sealss=8 During program load, one of the words in the input file was less than 9999 or greater than 9999 Execution Errors: Invalid Opcode --- ABEND Invalid opeo de An attempt was made to execute an unrecognizable instruction, the lemost two digits of the word was not a valid instruction. Addressability ** ABEND: add=2222011. Sy 27=6= * An attempt was made to letch an instruction from an invalid memory location. Division by 0 *** AEEND: attempted 4-125on Dy *** Attempt to divide by 0 Underflow ABEND: under?! ... The result of an arithmetic operation is less than 9999, and therefore would not fit into the accumulator Overflow NE vero The result of an arithmetic operation is greater than 9999, and therefore would not fit into the accumulator. ilegal input *** ABEND: 12aga1- *** During a HEAD instruction an attempt was made to read a value that was either less than 9999 or greater than 9999 6. Files You Must Write You will need to write three files for this assignment . am. This header file must contain all the define Statements that define the Simplesim's instruction set. i.e. de?ina READ 11. deina MRITS 12, etc. The header file should have an appropriate set of beeder guards to prevent it from being included multiple times in the same source file. ainplean. This header file should contain the class definition for a class called simpieaim. This class definition should contain the private data members described below under 7. Simulating the Simplesim. It should also contain public declarations fi.e., prototypes) for the four member functions whose definitions are contained in anpierin.cpe described below). The header file should have an appropriate set of header guards. implerincep This source file will contain function definitions for the following four member functions of the impresim class Splaas ::ample) This "default constructor Lakes no arguments and has no return value. Its job is to perform the initialization process for a simplesnobject described under 7.1. Initialize Simplesim. o boi sinplean:: 1024_program This member function reads an SML program som 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 it the load process abnormally terminated . Od sinpleasm::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. oda.plea.mdr) conas 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 arty of the data of the amplain object that calls it, it is declared to be cons Place the following two slede Statements at the top of this file, following any other required include statements that you have coded (conten, somasin, e...): #include This will ensure that the code that you write for your member functions will have access to the definition of the simplesin class and the define statements that define the Simplesim instruction set Note that there is no mention here of a masa () function for the program. That Tunction 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 simplesm. class during the build processinitiated by the make command. 7. Simulating the simplesim The as please class will need private data members that represent the memory and registers of the machine. You should use an array of integers length 100) to simulate the memory and live separate integer variables to simulate each of the live Simplesim registers. You might find it easiest to name the memory and register variables as follows: int nambay[2001 int acculatoa int natuton_counts: in natruction_regiates; in operation_code int operandi You should organize your program as a sequence of four steps initialization, koad, execute, and dump. Cach step is described in detail below. 7.1. Initialize Simplesim The default constructor for the amplasim dass simulates tuming the Simpletron ont. It is a simple, but necessary, step in which all five registers are initialized with zero and all 100 words of memory are initialized with the value 7777. The value 7777 was choser, in part, because the leftmost two digits (77) are not a valid instruction If you prefer the register data members can easily be initialized to when they are declared using C++115 "wrace or equal syntax. In that case, there's no need to initialize them again in the constructor 7.2. Load SML Program In the 20-3_P-og-an member function, you load the SML program into the Simplesim's memory. This requires you to read the program, one line at a time, from ade and stop when you encounter -99999. All input starts with the SML program, with one instruction (word) perline, and marks the end of the SML program with 99999. Load the SML program, each instruction into a word of memory, Starting at memory location and proceeding continuously in memory (not skipping arty memory locations) until the entire program has been loaded. This assignment is the first in a sequence of three. It is not strictly necessary to complete this one in order to do the other two, but the understanding you gain in completing this assignment will make writing the third assignment (a major project much easier. You will need to complete the second in the sequence in order to do the third. Ve start by peeling open" a computer, look at its internal structure, and introducing machine language (assembler level programming. Your assignment is to write a program that simulates a computer, one that is capable of executing machine language programs. 1. Initial Setup 1. Log in to Unix. 2. Run the setup script for Assignment 4 by typing: 2. Description of the Simplesim Computer this assignment you will write a program to simulate a fictional computer that we will call the Simplesim. As its name imples 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. The Simplesim has a 100 word memory and these words are referenced by their location numbers 00.01.... 99. Each word in the Simplesim's memory Calways a single signed four-digit decimal number) may be interpreted as an instruction to be executed, a data value, or may be uninitialized. The firsc register is the accumulator, which is just large enough to hold a single word. Words from memory must be placed into the accumulator in order to perform arithmetic on them or test their values. All arithmetic and branching is done using the accumulator The second register is the instruction counter, which is just large enough to hold a memory locations (a two digit number 00, 01.... 99). The instruction counter is used to hold the memory location of the next instruction to be executed. The third register is the instruction register, which, like the accumulator, is just large enough to hold a single word. The instruction register is used to hold a copy of the instruction (a word that was pulled out of memory that is currently being executed. The fourth and fifth registers are the operation code and operand, respectively. Each one is just large enough to hold hall of a word a two digit decimal number. The operation code and operand registers are used to split the instruction register in hall with the leftmost digits and sign of the instruction register going into the operation code and the rightmost digits gaing into the operand. For example, if the instruction register had +1009, the operation code would have +10 and the operand would have 09. Likewise, if the instruction register had 1201, the operation code would have 12 and the operand would have 01: 3. The Simplesim Machine Language (SML) ach instruction written in the Simplesim Machine Language (SML) occupies one word of the Simplesim's memory and hence instructions are signed four digit decimal numbers). The two leftmost digits of each SML instruction are the operation code lopcode), which specifies the operation to be performed. The two rightmost digits of an SML instruction are the operand, which is the memory location containing the word to which the operation applies. The complete set of SML instructions is described in the able that follows. Operation Code Meaning Input/Output Operations: =detina READ 11 Read a word into a specilic memory location da? DA MRITE 12 Print a word from a specific memory location Sidre/ Load Operations #define SCORE 21 Store the word in the accumulator into a specific memory location Edetina LOAD 22 Load a word from a specific memory location into the accumulator Arithmetic Operations se?ine ADD 22 Add a word in a specific memory location to the word in the accumulator (leave result in accumulator). Edeline SL3ZPACT 32 Subtract a word in a specific memory location from the word in the accumulator (leave result in accumulator), define BOLESSLY 33 Multiply a word in a specific memory location by the word in the accumulator leave result in accumulator #6. DIVIDE 34 Divide a word in a specific memory location into the word in the accumulator leave result in accumulator Transler of Control Operations #define BRANCH 41 Branch to a specific memory location datinA BRANCH ZERO 42 Branch to a specific memory location it the accumulator is zero. #define BRANCANE 43 Branch to a specific memory location if the accumulator is negative. 802.ne SALT 44 Hall, i.e, the program has completed its task (Read A Ve illustrate how the simplesim executes SML programs (using the instructions from the table above) with the use of two example SML programs. Consider the following SML program which reads two numbers and computes and prints their sum. Memory Location Word Instruction +1107 01 +1109 (Read B) 02 2207 (Load A) +3108 (Add D) 04 +2109 (Score) 05 +1209 (Write +4400 (Halt) 07 +0000 (Variable 08 +0000 (Variable 09 +0000 (Result C) xecution always begins al memory location Co. The word at memory location 00 +1107) is read and interpreted as an instruction. The leftmost two digits of the word (11) represent the instruction and the rightmost two digits (07) represent the instruction's operand. The first instruction is a SEAD operation. This reads a single word from the input file (explained in Section 4) and stores it in the memory location defined by the operand, in this case memory location 07. READ and B.ITE instructions always perate on memory locations. This completes the execution of the first instruction Processing continues by executing the next instruction found a memory location 01. The next instruction [+110B) reads a second word from the input file and stores it in memory location 08. The next instruction (+2207) is a LOAD operation with operand 07. It takes the word found at memory location 07 (the operand) and places it into the accumulator (recall that the accumulator is one of the five registers described in Section 1). A LOAD and Store operations move data in and out of the accumulator. the next instruction (3106) is an ADD instruction with operand 02. AR SML arithmetic instructions are performed using the word in the accumulator and the word identified by the operand and the result is always left in the accumulator. This instruction takes the word stored in memory location of the operand) adds to the value in the accumulator, and leaves the sum in the accumulator The next instruction (+2109) is a SCORE instruction which, like all STORE instructions, takes the word in the accumulator (the sum of the two inpul values and stores it in the memory location identified by the instruction's operand, in this case memory location 09. Then +1209, a TIRLITE instruction, prints output is explained in Section 5) the word found in memory location 09, which again is the sum of the lo input values. Finally instruction +4400, the HALS instruction, is executed which simply terminales The next instruction (+2109) is a STORE instruction which, like all stora instructions, Lakes the word in the accumulator (the sum of the two input values and stores it in the memory location identified by the instruction's operand, in this case memory location 09. Then +1209, a ELITE instruction, prints (output is explained in Section 5) the word found in memory location 09, which again the sum of the two input values. Finally instruction +4400, the HALT instruction, is executed which simply terminates the SML program (operand 00 is ignored for this instruction) Note that a single word in memory can be used to store a single instruction that is to be executed or a single variable that should never be interpreted as an instruction. None of the memory locations after the HD instruction (memory locations 07-09) were executed, however, they were important in the computation. Those words were used to store the program's variables and temporary results. All SML programs will partition" the Simplesim's memory in this way. The first words of memary Calways starting at memary location 00) are the instructions of the program and following that after the SALI instruction, is the data" part of the progtam. The intention, of course, is that only the "instructions of the program are to be executed, ie, each word interpreted as an SML instruction Now consider this second SML program that reads two numbers and prints the larger of the two Memory Location Word Instruction +1109 01 1110 (Read D) +2209 (Load A +3210 (Subtract 04 +4307 (Branch negative to 07) OS 1209 (Write A) +4400 (Halt) +1210 (Write B) 08 (Halt) 09 (Variable A) +0000 (Variable 00 (Read A) +4400 10 The first two instructions (+1109 and +1110) read two values and store them in memory locations 09 and 10, respectively. -2209 places the word al memory location 09 (the first input value) into the accumulator. +3210, SUSTRACS Instruction takes the word al memory location 10 (the second input value), subtracts it from the accumulator, and leaves the result in the accumulator +4307 (BRANCENEC) is a conditional branch instruction, much like an "il" statement in Ch. All conditional branch instructions are based on the accumulator. The Ras instruction, which als like a gato", is the only branch instruction that ignore the accumulator, it is simply an unconditional branch. If the value in the accumulator is negative, which in this case means the second input value was the largest, then the next instruction that gets executed is the one al memory location 07 (the operand if the value in the accumulator is or greater meaning the liest input value was greater than or equal to the second, then execution continues with the next statement, i.e., no branching. If the branch was taken then the value at memory location 10 (the second input value is printed and the program terminates. Otherwise the value at memory location 09 (the first input value) Sprinted and the program terminales Note how the SML program is written. It partitions the Simplesim's memory into two distinct parts, the program" (locations 00 OB) and the data" (locations 09-10). This SML program, unlike the first has two HALS instructions. This is okay, only one of them will be executed. The point is that BALI instructions are used to prevent the execution of the program from wandering into the data portion of the program. 4. Input 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 (ie, 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. 1207 110 2103 -99999 Note that each line of the input me, other than 99999 which is used to denate the end of program and not intended to be placed into the Simplesimi'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 ine. All input files to your program have 99999 alter 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 WISZ 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. When the HALE Statement is executed, your program should print the following line *** Simple in Gaution ninated -- 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 aimpierim and the name of the SML program ie above is aam.nl, then the output of your programm must look exactly like this. =123456 ving:-/0201243/Aasion 4 / omplain aan SEAD: -0003 READ: 0015 - Simplesmention Caminated . -0010 REGISTESS: acownslator: instruction_counter instruction_regiates: pertson_code: operand: -4400 44 00 SEMORY 0-1107 -1108 -2207 3303 -2103 -1205 -4400-2005 +0013-0010 10 Find a 30 -7777-7777 +7717 +1777 - 1977 -7777-777777777777 +1777 40 -7777-7777-7777 +7777-7777-7777-777777777777-7777 50 -7777-777777777777-7777-7777-7777777777777777 60 -7777-77777777 +7777-7777-7777-7777777777777777 70 -77777777777777777-7777-7777-77777777777777777 80 -1777-77777777-7777 - 1777-7777-777777777777 +1777 90 -1771-77777777777777777 +7777-7777-7777777777777777-7777 =12345 Etag:-/ee1241/Asn4 One of the first things that your programs will do is read the SML pragrarn 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 lie, 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 SMIL program laad, 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 Io abend, in which case processing slops immediately An example of this is an attempt to divide by O. In that case, the Simplesim should print an appropriate abend message stop execution and dump the contents of the machine. [very execution of your program normal termination of the SML program or SML program abend) ends with a dump of the Simplesim. A summary of the possible abend conditions (program load and execution errors) with their error messages appear in the following table Note that all error messages must appear exactly as they appear in the table. Condition Error Message Description Program Load Errors: Program too big - ABEND: Pon load: pom teo lage *** The program is too big more than 100 words) to fit into memory Invalid word *** ABEND: Pon load: Sealss=8 During program load, one of the words in the input file was less than 9999 or greater than 9999 Execution Errors: Invalid Opcode --- ABEND Invalid opeo de An attempt was made to execute an unrecognizable instruction, the lemost two digits of the word was not a valid instruction. Addressability ** ABEND: add=2222011. Sy 27=6= * An attempt was made to letch an instruction from an invalid memory location. Division by 0 *** AEEND: attempted 4-125on Dy *** Attempt to divide by 0 Underflow ABEND: under?! ... The result of an arithmetic operation is less than 9999, and therefore would not fit into the accumulator Overflow NE vero The result of an arithmetic operation is greater than 9999, and therefore would not fit into the accumulator. ilegal input *** ABEND: 12aga1- *** During a HEAD instruction an attempt was made to read a value that was either less than 9999 or greater than 9999 6. Files You Must Write You will need to write three files for this assignment . am. This header file must contain all the define Statements that define the Simplesim's instruction set. i.e. de?ina READ 11. deina MRITS 12, etc. The header file should have an appropriate set of beeder guards to prevent it from being included multiple times in the same source file. ainplean. This header file should contain the class definition for a class called simpieaim. This class definition should contain the private data members described below under 7. Simulating the Simplesim. It should also contain public declarations fi.e., prototypes) for the four member functions whose definitions are contained in anpierin.cpe described below). The header file should have an appropriate set of header guards. implerincep This source file will contain function definitions for the following four member functions of the impresim class Splaas ::ample) This "default constructor Lakes no arguments and has no return value. Its job is to perform the initialization process for a simplesnobject described under 7.1. Initialize Simplesim. o boi sinplean:: 1024_program This member function reads an SML program som 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 it the load process abnormally terminated . Od sinpleasm::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. oda.plea.mdr) conas 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 arty of the data of the amplain object that calls it, it is declared to be cons Place the following two slede Statements at the top of this file, following any other required include statements that you have coded (conten, somasin, e...): #include This will ensure that the code that you write for your member functions will have access to the definition of the simplesin class and the define statements that define the Simplesim instruction set Note that there is no mention here of a masa () function for the program. That Tunction 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 simplesm. class during the build processinitiated by the make command. 7. Simulating the simplesim The as please class will need private data members that represent the memory and registers of the machine. You should use an array of integers length 100) to simulate the memory and live separate integer variables to simulate each of the live Simplesim registers. You might find it easiest to name the memory and register variables as follows: int nambay[2001 int acculatoa int natuton_counts: in natruction_regiates; in operation_code int operandi You should organize your program as a sequence of four steps initialization, koad, execute, and dump. Cach step is described in detail below. 7.1. Initialize Simplesim The default constructor for the amplasim dass simulates tuming the Simpletron ont. It is a simple, but necessary, step in which all five registers are initialized with zero and all 100 words of memory are initialized with the value 7777. The value 7777 was choser, in part, because the leftmost two digits (77) are not a valid instruction If you prefer the register data members can easily be initialized to when they are declared using C++115 "wrace or equal syntax. In that case, there's no need to initialize them again in the constructor 7.2. Load SML Program In the 20-3_P-og-an member function, you load the SML program into the Simplesim's memory. This requires you to read the program, one line at a time, from ade and stop when you encounter -99999. All input starts with the SML program, with one instruction (word) perline, and marks the end of the SML program with 99999. Load the SML program, each instruction into a word of memory, Starting at memory location and proceeding continuously in memory (not skipping arty memory locations) until the entire program has been loaded
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