( 12 )
Previous Table Of Contents Next


Data Memory

Data Memory consists of storage locations where you can place and later recall arbitrary values. In the case of the RPN calculator, the values that can be stored in data memory are numbers, but in other computers you can put text, pictures, sounds, and other objects into data memory.

The RPN calculator offers a data memory large enough to hold 30 numbers. These 30 storage locations are illustrated below.

A Register window will open to display the contents of these 30 data memory locations (called registers) anytime you click on the SST key. But this window will automatically close when you next enter Program mode. You can request that the Registers window always remain open via a program option found on the dialog box you get by selecting View/Options from the menu bar.

There are two methods for accessing the data memory of the RPN calculator: direct addressing and indirect addressing. Direct addressing is the simpler technique (hence the name). But unfortunately direct addressing cannot reach all 30 of the data memory locations. You copy the number in the X stack location to data memory location 0 thru 9 via the generic statement STO n where n is a single digit (i.e., 0 through 9). You recall (to the X stack location) a number from data memory location 0 thru 9 via the generic statement RCL n where n is a single digit. You place a number in data memory location 10 thru 19 via the generic statement STO .n where n is a single digit. You recall a number from data memory location 10 through 19 via the generic statement RCL .n where n is a single digit. You cannot reach data memory location 20 through 29 using direct addressing.

Let's first practice with these new instructions. Click on the SST key to open the Registers window (it doesn't matter what program is in program memory since we will ignore the consequence of whatever single statement the SST keystroke just executed). Depending upon what your calculator has been doing, you may already see numbers other than 0 in data memory. You can clear all of data memory via the keystroke ClearREG (, note that this keystroke requires the f prefix).

The keystroke sequence 5, STO 5 will place the number 5 into data memory location 5. The keystroke sequence 15, STO .5 will place the number 15 into data memory location 15.

The generic instruction STO .n probably looks like a bit of a hack since it is not immediately obvious that the decimal point substitutes for a leading 1. But the only alternative would have been to define the generic instruction as STO nn rather than STO n meaning that you always had to type 2 decimal digits. This would have had the benefit of allowing you to directly reach all 30 data memory locations but would also have had the drawback that you would have to type STO 00 to write to data memory location 0. Since you rarely need more than 10 data memory locations anyway, getting rid of one keystroke was a defensible design decision.

Now that we know about data memory let's rewrite our SecondOrderEq.txt example program. You'll remember that we needed to make a temporary copy of the x axis value passed into the program in order that we wouldn't lose this x axis value when we computed the x2 term. In the original SecondOrderEq.txt program we kept this temporary copy on the operand stack. In the new SecondOrderEq2.txt program we will place this temporary copy into data memory location 0 which is also known as register 0.

; file SecondOrderEq2.txt ; This RPN calculator program computes the second order eq.: ; y = f(x) = 1x^2 + 2x + 3 ; To run the program enter an x value into the X stack location ; and then type GSB 0 (alternatively, type GTO .00 followed ; by R/S). When the program stops the corresponding y value ; is visible in the X stack location. LBL 0 ; program entry point, at this time X = x STO 0 ; preserve initial x value in Reg[0] x^2 ; X = x^2 +2. ; X = 2, Y = x^2 ENTER ; X = 2, Y = 2, Z = x^2 RCL 0 ; X = x, Y = 2, Z = x^2 * ; X = 2x, Y = x^2 +3. ; X = 3, Y = 2x, Z = x^2 + ; X = 2x+3, Y = x^2 + ; X = x^2+2x+3 R/S ; we're done

Just for fun we also made another change: we delayed combining the three terms in x2 + 2 * x + 3 until the very end of the program. These three terms all reside in the operand stack until the back-to-back + keystrokes that end the program.

The new program is 1 statement longer than the original program which only proves how handy the operand stack is as a temporary repository of operands (which is exactly what it was intended for).

Thus far we have used the operand stack to pass run-time parameters into our programs. Since data memory is accessible to both the human operator and to the running program it too can be used as the mechanism for passing parameters to a program. In fact, if you need to pass more than four parameters then you will certainly have to employ data memory to do it.

Let's rewrite the SecondOrderEq.txt example program once more, this time requiring the human operator to place his intended x axis value into data memory location 0 before he initiates the program. The new program is shown below:

; file SecondOrderEq3.txt ; This RPN calculator program computes the second order eq.: ; y = f(x) = 1x^2 + 2x + 3 ; To run the program enter an x value into data memory location 0 ; (register 0) and then type GSB 0 (alternatively, type ; GTO .00 followed by R/S). When the program stops the ; corresponding y value is visible in the X stack location. LBL 0 ; program entry point, at this time Reg[0] = x RCL 0 ; so now X = x x^2 ; X = x^2 +2. ; X = 2, Y = x^2 ENTER ; X = 2, Y = 2, Z = x^2 RCL 0 ; X = x, Y = 2, Z = x^2 * ; X = 2x, Y = x^2 +3. ; X = 3, Y = 2x, Z = x^2 + ; X = 2x+3, Y = x^2 + ; X = x^2+2x+3 R/S ; we're done

Remember that to employ this program to solve the second order equation for the y value corresponding to x = 5 you must use the keystroke sequence 5, STO 0, GSB 0.

I am showing you all these alternatives so you will understand that there are many ways to accomplish a given programming task. In general it is better to design a more complicated program if this will reduce the complexity visible to the operator of that program. This makes sense because programs are written once but run many times. Using this yardstick we would reject this latest SecondOrderEq3.txt example program since the operator is burdened with more keystrokes to initiate the program.

I have mentioned that you can also access data memory using something called indirect addressing but I have not yet explained this. I am going to delay discussing this technique until the next section where we discuss loops. In a program loop, indirect addressing can do something direct addressing cannot: a single statement can interact with any number of data memory locations.


Previous Table Of Contents Next