Answered step by step
Verified Expert Solution
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 sentinelcontrolled loop to read positive numbers. Compute and display their
sum.
b Use a countercontrolled 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.
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 objectoriented software model of the Simpletron of Exercise 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
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 to stop entering your program.
Your application should simulate the memory of the Simpletron with a onedimensional array mem
ory that has elements. Now assume that the simulator is running, and let's examine the dialog
as we enter the program of Fig. Exercise :
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 is input, the program
should display the following:
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 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 ie
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, in memory location oo
This procedure is called an instructionexecution 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 ;
operand instructionRegister ;
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 operations of SML In the switch state.
ment, the behavior of various SML instructions is simulated as shown in Fig. 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 memoryoperand;
halt: Terminate the SML program's execution and display the following message:
Simpletron execution terminated
Fig. 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. A dump after executing a
Simpletron program would show the actual values of instructions and data values at the moment
execution terminated.
REGISTERS :
MEMORY:
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