Tuesday, November 8, 2011

HP 15C Programming Tutorial - Part 1: The Stack

Welcome to Programming with the 15C

This tutorial series covers keystroke programming with the Hewlett Packard 15C calculator. This is a powerful scientific calculator that is RPN (Reverse Polish Notation) operated. Features include complex numbers, statistics, matrices, integration, and the ability to solve equations.

Calculator.org gives a short introduction to RPN here.

I also give a short RPN tutorial on my blog, which can be found here.

The HP 15C was originally released in 1982 and proved to be one of the most popular calculators. In fact, it was so popular that demand for the HP 15C lasted well after Hewlett Packard ended its original production run in 1989. In September 2011, Hewlett Packard released a HP 15C Limited Edition calculator, that works just like the original, except it is much faster. We can only hope that Hewlett Packard considers making the HP 15C a permanent production once again.

More information of the HP 15C calculator can be found here.

About Memory

The calculator has has amount 67 storage registers. Each storage register can contain a number in memory, or 7 bytes of programming.

At default, the HP 15C allocates 19 storage registers as numeric storage, and 46 storage registers available for either programming or numeric storage. 2 storage registers, R0 and RI, will always be used for numeric storage. Our tutorial will use this default setting.

About Part 1

The first lesson will briefly cover the basics of the stack - which a working knowledge is essential to successfully programming the HP 15C.
The Stack

The HP 15C calculator contains four stacks: T, Z, Y, and X. The X stack is what you see in the display. We will go over how the stack is affected by the common operations of the calculator.

T
-------
Z
-------
Y
-------
X


[ENTER]

The [ENTER] key does many functions. First, it terminates entry of a number and prepares the calculator for another. Second, the number that was just entered not only stays in the X register, but is also copied to the Y register. The next number you enter replaces the contents of the X register. The contents of register T are lost.


T:  contents of Z are moved here
-------
Z:  contents of Y are moved here
-------
Y:  the number just entered is copied here 
-------
X:  ready for the next number


One-Number Functions

One-number functions, f(X), operate on the contents of the X register and returns the result on the X register. One-number functions include √, x^2, LN, e^x, LOG, 10^x, 1/x, CHS, SIN, SIN^-1, COS, COS^-1, TAN, TAN^-1, HYP (trig), HYP^-1 (trig), ABS, FRAC, INT, x!, → H (hours), → HMS (hours, minutes, seconds), → RAD, and → DEG.


T:  unaffected
-------
Z:  unaffected
-------
Y:  unaffected
-------
X:  f(X)


Two-Number Functions

Two-number functions, g(X,Y), operate on the contents of the X and Y registers and returns the result on the X register. The contents of Z register are moved to the Y register, and the contents of the T register are copied to the Z register.

Two-number functions include +, - (returns Y - X), × , ÷ (returns Y ÷ X), y^x, % (returns Y * X/100), Px,y (permutation), Cx,y (combination), and ∆% (percent change).


T:  unaffected
-------
Z: contents of T are copied here
-------
Y: contents of Z are moved here
-------
X: the result of g(X,Y)


π and Last x

Obviously, the key sequence [g] [EEX] ( π ) enters π (pi) on the X stack.

The key sequence [g] [ENTER] (LST x) recalls the value that was in the display prior to the execution of a numeric operation. LST x is good for correct errors and faster calculations should a number need to be repeated again.

Both π and LST x push the stack up. The contents of register T are lost.


T: contents of Z are moved here
-------
Z: contents of Y are moved here
-------
Y: contents of X are moved here
-------
X:  π or Last X


Polar and Rectangular Conversion

[f] [ 1 ] (→ R ) is the Polar to Rectangular conversion function.


T:  unaffected
-------
Z:  unaffected
-------
Y:  y is converted to θ
-------
X:  x is converted to r


[g] [ 1 ] (→ P ) is the Rectangular to Polar conversion function.


T:  unaffected
-------
Z:  unaffected
-------
Y:  θ is converted to y
-------
X:  r is converted to x


The [x<>y] Key - Swap

The [x<>y] switches the contents both registers X and Y. This key is useful in ordering values in the correct order and viewing two-result operations (such as the rectangular and polar conversions).


T:  unaffected
-------
Z:  unaffected
-------
Y:  contents of X are moved here
-------
X:  contents of Y are moved here


The Roll Keys

[R ↓ ] is the roll down key. Pressing this "rolls" the contents of the stack down one register. Pressing [R ↓ ] four times allows you to view the entire stack.


T:  contents of X are moved here
-------
Z:  contents of T are moved here
-------
Y:  contents of Z are moved here
-------
X:  contents of Y are moved here


The key sequence [g] [R ↓ ] (R ↑ ) is the roll up key sequence, which "rolls" the contents of the stack up one register. Executing this key sequence four times allows you to view the entire stack.


T:  contents of Z are moved here
-------
Z:  contents of Y are moved here
-------
Y:  contents of X are moved here
-------
X:  contents of T are moved here

Practice Tip: When designing a program, sometimes I find it helpful to draw the stack in a horizontal matter (X | Y | Z | T) to see how each program step affects the stack.

Well, that is it for Part 1. Next time, we actually start programming. I hope this helps you understand the basics of the stack. Until next time,

Eddie



This tutorial is the property of Edward Shore - mass duplication and reproduction requires express permission of the author. © 2011