Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Now write SML programs to accomplish each of the following tasks: a ) Use a sentinel - controlled loop to read 1 0 positive numbers.

Now write SML programs to accomplish each of the following tasks:
a) Use a sentinel-controlled loop to read 10 positive numbers. Compute and display their
sum.
b) Use a counter-controlled loop to read seven numbers, some positive and some negarive,
and compute and display their average.
c) Read a series of numbers, and determine and display the largest number. The first num-
ber read indicates how many numbers should be processed.
1.37(Computer Simulator) In this problem, you're going to build your own computer. No,
you'll not be soldering components together. Rather, you'll use the powerful technique of software-
based simulation to create an object-oriented software model of the Simpletron of Exercise 7.36. Your
Simpletron simulator will turn the computer you're using into a Simpletron, and you'll actually be
able to run, test and debug the SML programs you wrote in Exercise 7.36.
When you run your Simpletron simulator, it should begin by displaying:
Welcome to Simpletronl
Please enter your program one instruction
*th (or data word) at a time. I will display
the location number and a question mark (?).
ow You then type the word for that location.
& Type -99999 to stop entering your program.
Your application should simulate the memory of the Simpletron with a one-dimensional array mem-
ory that has 100 elements. Now assume that the simulator is running, and let's examine the dialog
as we enter the program of Fig. 7.35(Exercise 7.36):
Your program should display the memory location followed by a question mark. Each value to the
right of a question mark is input by the user. When the sentinel value -99999 is input, the program
should display the following:
*4 Program loading completed
a Program execution begins
The SML program has now been placed (or loaded) in array memory. Now the Simpletron exe-
cutes the SML program. Execution begins with the instruction in location 00 and, as in Java, con-
tinues sequentially, unless directed to some other part of the program by a transfer of control.
Use the variable accumulator to represent the accumulator register. Use the variable instruc-
tioncounter to keep track of the location in memory that contains the instruction being per-
formed. Use the variable operationCode to indicate the operation currently being performed (i.e.,
the left two digits of the instruction word). Use the variable operand to indicate the memory loca-
tion on which the current instruction operates. Thus, operand is the rightmost two digits of the
instruction currently being performed. Do not execute instructions directly from memory. Racher,
transfer the next instruction to be performed from memory to a variable called instructionRegis-
ter. Then pick off the left two digits and place them in operationCode, and pick off the right two
digits and place them in operand. When the Simpletron begins execution, the special registers are
all initialized to zero.
Now, let's walk through execution of the first SML instruction, +1009 in memory location oo.
This procedure is called an instruction-execution cycle.
The instructionCounter tells us the location of the next instruction to be performed.
fetch the contents of that location from memory by using the Java statement
instructionRegister = memory [instructionCounter];
The operation code and the operand are extracted from the instruction register by the statements
operationCode = instructionRegister /100;
operand = instructionRegister %100;
Now the Simpletron must determine that the operation code is actually a read (versus a write, a
load, and so on). A switch differentiates among the 12 operations of SML. In the switch state.
ment, the behavior of various SML instructions is simulated as shown in Fig. 7.36. We discuss
branch instructions shortly and leave the orhers to you.
rend:
Display the prompt "Enter an integer", then input the integer and store it
in location memory [operand].
load:
accumulator = memory [];
add:
accumulator += memory[operand];
halt: , Terminate the SML program's execution and display the following message:
Simpletron execution terminated
Fig. 7.36| Behavior of several SML instructions in the Simpletron.
When the SML program completes execution, the name and contents of each register as well
as the complete contents of memory should be displayed. Such a printout is often called a com-
puter dump (no, a computer dump is not a place where old computers go). To help you program
your dump method, a sample dump format is shown in Fig. 7.37. A dump after executing a
Simpletron program would show the actual values of instructions and data values at the moment
execution terminated.
REGISTERS :
MEMORY:
40+0000+0000+0000+0000+0000+0000+0000+0000+0000+0000
50+0000+0000+0000+0000+0000+0000+0000+0000+0000+0000
70+0000+0000+0000+0000+0000+0000+0000+0000+0000+0000
80+0000+0000+0000+0000+0000+000+0000+0000+000+0000+0000
90+0000+0000+0000+0

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

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions

Question

Question 1 (a2) What is the reaction force Dx in [N]?

Answered: 1 week ago