Java Reference
In-Depth Information
Location
Number
Instruction
05
(Write C)
+1109
06
(Halt)
+4300
07
(Variable A)
+0000
08
(Variable B)
+0000
09
(Result C)
+0000
Fig. 7.34 | SML program that reads two integers and computes their sum. (Part 2 of 2.)
The second SML program (Fig. 7.35) reads two numbers from the keyboard and determines
and displays the larger value. Note the use of the instruction +4107 as a conditional transfer of con-
trol, much the same as Java's if statement.
Location
Number
Instruction
+1009
00
(Read A)
01
+1010
(Read B)
+2009
02
(Load A)
03
+3110
(Subtract B)
+4107
04
(Branch negative to 07)
05
+1109
(Write A)
+4300
06
(Halt)
07
+1110
(Write B)
+4300
08
(Halt)
09
+0000
(Variable A)
+0000
10
(Variable B)
Fig. 7.35 | SML program that reads two integers and determines the larger.
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 negative,
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.
7.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 Simpletron! ***
*** Please enter your program one instruction ***
*** (or data word) at a time. I will display ***
*** the location number and a question mark (?). ***
*** You then type the word for that location. ***
*** Type -99999 to stop entering your program. ***
 
Search WWH ::




Custom Search