Java Reference
In-Depth Information
At this point, you should implement your Simpletron simulator and run each of the SML
programs you wrote in Exercise 7.36. If you desire, you may embellish SML with additional fea-
tures and provide for these features in your simulator.
Your simulator should check for various types of errors. During the program-loading phase,
for example, each number the user types into the Simpletron's memory must be in the range -9999
to +9999 . Your simulator should test that each number entered is in this range and, if not, keep
prompting the user to re-enter the number until the user enters a correct number.
During the execution phase, your simulator should check for various serious errors, such as
attempts to divide by zero, attempts to execute invalid operation codes, and accumulator overflows
(i.e., arithmetic operations resulting in values larger than +9999 or smaller than -9999 ). Such seri-
ous errors are called fatal errors. When a fatal error is detected, your simulator should display an
error message, such as
*** Attempt to divide by zero ***
*** Simpletron execution abnormally terminated ***
and should display a full computer dump in the format we discussed previously. This treatment
will help the user locate the error in the program.
7.38 (Simpletron Simulator Modifications) In Exercise 7.37, you wrote a software simulation of a
computer that executes programs written in Simpletron Machine Language (SML). In this exercise,
we propose several modifications and enhancements to the Simpletron Simulator. In the exercises of
Chapter 21, we propose building a compiler that converts programs written in a high-level program-
ming language (a variation of Basic) to Simpletron Machine Language. Some of the following modi-
fications and enhancements may be required to execute the programs produced by the compiler:
a) Extend the Simpletron Simulator's memory to contain 1,000 memory locations to en-
able the Simpletron to handle larger programs.
b) Allow the simulator to perform remainder calculations. This modification requires an
additional SML instruction.
c) Allow the simulator to perform exponentiation calculations. This modification requires
an additional SML instruction.
d) Modify the simulator to use hexadecimal rather than integer values to represent SML
instructions.
e) Modify the simulator to allow output of a newline. This modification requires an addi-
tional SML instruction.
f) Modify the simulator to process floating-point values in addition to integer values.
g)
Modify the simulator to handle string input. [ Hint: Each Simpletron word can be di-
vided into two groups, each holding a two-digit integer. Each two-digit integer repre-
sents the ASCII (see Appendix B) decimal equivalent of a character. Add a machine-
language instruction that will input a string and store the string, beginning at a specific
Simpletron memory location. The first half of the word at that location will be a count
of the number of characters in the string (i.e., the length of the string). Each succeeding
half-word contains one ASCII character expressed as two decimal digits. The machine-
language instruction converts each character into its ASCII equivalent and assigns it to
a half-word.]
h)
Modify the simulator to handle output of strings stored in the format of part (g). [ Hint:
Add a machine-language instruction that will display a string, beginning at a certain
Simpletron memory location. The first half of the word at that location is a count of the
number of characters in the string (i.e., the length of the string). Each succeeding half-
word contains one ASCII character expressed as two decimal digits. The machine-lan-
guage instruction checks the length and displays the string by translating each two-digit
number into its equivalent character.]
 
Search WWH ::




Custom Search