The Museum of HP Calculators


HP-25/25C Programming

Contents:

Features

Basic Programming

Entering And Running A Sample Program

A simple program is essentially just the keystrokes you would press to solve the program manually. The calculator remembers a sequence of keys and executes them in order at the touch of a key. In the simplest programs, there are no additional steps required at all.

To enter a program, slide the PRGM-RUN switch to PRGM. Then press f PRGM to clear program memory and to set the calculator to the beginning.

With the PRGM-RUN switch set to PRGM (program) the number you see on the left side indicates the step number. As keystrokes are entered, their row/column codes will be displayed on the right. Step 00 is really just a placeholder. The first keys you press will go into step 01.

Enter the program below to compute the area of a circle:

g x2       These three instructions
g π        are just the normal keystrokes
×          for computing the area given the radius in X

There is no need to "end" your program because when the program memory is cleared with f PRGM, it is filled with GTO 00s. (These display as 13 00.)

Now set the PRGM-RUN switch to RUN and set the program counter by pressing GTO 00 or f PRGM (your choice). To run the program, key in a radius and press R/S. After the display stops flashing, the area is displayed. The program can be run as many times as you like by entering new values and pressing R/S. For many simple programs, that's all you need to know!

Stopping, Interrupting and Entering Data

Many programs only require data to be entered at the beginning as the one above did. Remember that you can use the stack and store values in registers before execution. You can also enter R/S instructions into the program to allow additional data to be entered. The user can enter the data and then press R/S to resume. If you create a program that runs for too long (possibly due to an infinite loop) you can stop it by pressing R/S and if necessary, resume it by pressing R/S again. If you press R/S in the middle of a program, you can see where the program is executing by pressing and holding SST (see below) or switching to PRGM mode.

Stepping And Editing programs

The following commands are used to edit or step through programs and are not recordable.

GTO nn can be used in run mode to position the calculator to step nn. The calculator can then be switched to PRGM mode for editing at that step. Unlike the instructions above, this one is recordable so the position of the PRGM-RUN must be properly set.

Entering an instruction causes the new instruction to be placed after the instruction displayed and overwriting the following instruction. To replace a single instruction, display the instruction before the error and key in the correct instruction which will replace the error. If you find that you need to add instructions to a program, you can either rewrite it from the point of the error on down, or you can insert a GTO nn at the point where the new instructions would be needed, perform the new steps elsewhere and use a GTO to go back to the step after the first GTO. Remember to include the instruction that was overwritten by the first GTO in your new block of code. For example:

Original code;

...
10 -
11 STO 1      Oops! Need to square x and take the log before storing!
12 RCL 2
...

Patched code:

...
10 -
11 GTO 40     Overwrite STO 1 with a jump to some unused memory
12 RCL 2
...
40 g x2       The new steps
41 f log
42 STO 1      The step overwritten by GTO 40
43 GTO 12     Return to the normal program flow

Programming Techniques

Addressing

The HP-25 uses step addressing allowing you to jump to any line.

Jumps

The program below adds 1 to the X register, displays it for a second and then does it again "forever". Key it in after switching to PRGM mode and pressing f PRGM:

1             top of the loop
+
f PAUSE       display for a second
GTO 01        loop

Now switch to RUN mode, press GTO 00, enter a number and press R/S. When you get tired of it, press R/S again to stop it. (Note that you really didn't have to press GTO 00 in this case because when you left PRGM mode, you left the calculator on a GTO 01 instruction. Had you pressed R/S, it would have started by jumping to step 01 and working normally anyway. Still it's a good idea to get in the habit of pressing GTO 00 or f PRGM after switching to RUN mode.)

Conditional Tests and Flags

The HP-25 has instructions for comparing X to Y and X to 0. If the comparison is true the calculator executes the next instruction. If the comparison is false the calculator skips the next instruction.

The next instruction is most commonly a GTO like:

g X=0
GTO 15     Go to step 15 if X is equal to zero
STO 2      The line above is skipped and execution continues here
           if x is not zero. 

This example computes the arc sine of a value in X (-1 ≤ x ≤ 1). If the result is less than zero, it adds 360 to the angle. Switch to PRGM mode, press f PRGM and then enter:

g SIN-1       Calculate arc sine
g x≥0         Compare to zero
GTO 00        If greater than zero, display result and stop
3
6
0
+             Otherwise add 360 to result

Switch to RUN mode, press f PRGM so the calculator goes to step 00 and press g DEG to set degrees mode. Now press .5 R/S to see a result of 30 and .5 CHS R/S to see a result of 330.

Input/Output

R/S can be used as an instruction or pressed from the keyboard. If a program is stopped, pressing R/S starts it. If the program is running, pressing R/S stops it. An R/S can also be inserted into a program to allow the user to input or record data.

For example, this program accepts the length and radius of a cylinder. It computes the area of the base and stops to allow the answer to be recorded. When the user restarts it, it computes the volume.

g x2    Radius squared
g π 
×       Area of the base
R/S     Allow user to record it
×       Multiply by length still on the stack

Slide the PRGM-RUN switch to RUN, press f PRGM, key in a length and press ENTER. Then key a radius and press R/S. After the area is displayed press R/S again to display the volume.

The HP-25 has an f PAUSE instruction which can be used to display the X register for a second and then automatically continue.

Go back to the HP-25
Go back to the HP-25C
Go back to the software library
Go back to the main exhibit hall