Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use C++ We are going to create Simpletron. Simpletron is a simple -but powerful- computer. The Simpletron runs programs written in Simpletron Machine Language-SML. The

Use C++

We are going to create Simpletron. Simpletron is a simple -but powerful- computer. The Simpletron runs programs written in Simpletron Machine Language-SML. The Simpletron contains an accumulatora special register in which information is put before the Simpletron uses that information in calculations or examines it in various ways. All information in the Simpletron is handled in terms of words. A word is a signed four-digit decimal number, such as +3364, -1293, +0007, -0001, etc. The Simpletron is equipped with a 100-word memory, and these words are referenced by their location numbers 00, 01, , 99. Before running an SML program, we must load, or place, the program into memory. The first instruction (or statement) of every SML program is always placed in location 00. The simulator will start executing at this location. Each instruction written in SML occupies one word of the Simpletrons memory; thus, instructions are signed four-digit decimal numbers. Assume that the sign of an SML instruction is always plus, but the sign of a data word may be either plus or minus. Each location in the Simpletrons memory may contain an instruction, a data value used by a program or an unused (and hence undefined) area of memory. The first two digits of each SML instruction are the operation code that specifies the operation to be performed. The last two digits of an SML instruction are the operandthe address of the memory location containing the word to which the operation applies. SML operation codes are shown in the following table: Simpletron Machine Language (SML) operation codes. Operation code Meaning Input/output operations const int read{10}; Read a word from the keyboard into a specific location in memory. const int write{11}; Write a word from a specific location in memory to the screen. Load and store operations const int load{20}; Load a word from a specific location in memory into the accumulator. const int store{21}; Store a word from the accumulator into a specific location in memory. Arithmetic operations const int add{30}; Add a word from a specific location in memory to the word in the accumulator (leave result in accumulator). const int subtract{31}; Subtract a word from a specific location in memory from the word in the accumulator (leave result in accumulator). const int divide{32}; Divide a word from a specific location in memory into the word in the accumulator (leave result in accumulator). const int multiply{33}; Multiply a word from a specific location in memory by the word in the accumulator (leave result in accumulator). Transfer-of-control operations const int branch{40}; Branch to a specific location in memory. const int branchneg{41}; Branch to a specific location in memory if the accumulator is negative. const int branchzero{42}; Branch to a specific location in memory if the accumulator is zero. const int halt{43}; Haltthe program has completed its task.

SML Examples Example 1 The first SML Example reads two numbers from the keyboard and computes and displays their sum. The instruction +1007 reads the first number from the keyboard and places it into location 07 (which has been initialized to zero).

Instruction +1008 reads the next number into location 08. The load instruction, +2007, places (copies) the first number into the accumulator. And the add instruction, +3008, adds the second number to the number in the accumulator. All SML arithmetic instructions leave their results in the accumulator. The store instruction, +2109, places (copies) the result back into memory location 09. Then the write instruction, +1109, takes the number and displays it (as a signed four-digit decimal number). The halt instruction, +4300, terminates execution.

SML Example 1. Location Number Instruction

00 +1007 (Read A)

01 +1008 (Read B)

02 +2007 (Load A)

03 +3008 (Add B)

04 +2109 (Store C)

05 +1109 (Write C)

06 +4300 (Halt)

07 +0000 (Variable A)

08 +0000 (Variable B)

09 +0000 (Result C)

Example 2 This example eads two numbers from the keyboard, then determines and displays the larger value. Note the use of the instruction +4107 as a conditional transfer of control, much the same as C++s if statement.

Location Number Instruction

00 +1009 (Read A)

01 +1010 (Read B)

02 +2009 (Load A)

03 +3110 (Subtract B)

04 +4107 (Branch negative to 07)

05 +1109 (Write A)

06 +4300 (Halt)

07 +1110 (Write B)

08 +4300 (Halt)

09 +0000 (Variable A)

10 +0000 (Variable B) PartI write SML programs to accomplish each of the following tasks:

Use a sentinel-controlled loop to read positive numbers and compute and display their sum. Terminate input when a negative number is entered.

Use a counter-controlled loop to read seven numbers, some positive and some negative, and compute and display their average.

Read a series of numbers, and determine and display the largest number. The first number read indicates how many numbers should be processed.

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

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

4. How do rules guide verbal communication?

Answered: 1 week ago