let’s create a computer called the simpletron. as its name
let’s create a computer called the simpletron. as its name implies, it’s a simple, but powerful, machine. the simpletron runs programs written in the only language it directly understands: simpletron machine language (sml).the simpletron contains an accumulator—a special register in which information is put before the simpletron uses that information in calculations or examines it in various ways. all the information in the simpletron is handled in terms of words. a word is a signed four-digit decimal number, such as +3364, -1293, +0007 and -0001. 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 simpletron’s memory (and hence instructions are signed four-digit decimal numbers).we shall 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 simpletron’s 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 specifying the operation to be performed. sml operation codes are summarized in fig. 7.33.the last two digits of an sml instruction are the operand—the address of the memory location containing the word to which the operation applies. let’s consider several simple sml programs.the first sml program (fig. 7.34) 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 0). then instruction +1008 reads the next number into location 08. the load instruction, +2007, puts 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 the result back into memory location 09, from which the write instruction, +1109, takes the number and displays it (as a signed four-digit decimal number). the halt instruction, +4300, terminates execution.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 control, much the same as java’s if statement.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 number read indicates how many numbers should be processed.
Price Type: Negotiable
Total Proposals: 2
1 Current viewersl
44 Total views