RPN Advanced 42 manual · Chapter 16 of 18
Programming
Record keystrokes as a program: labels, running, loops, tests, subroutines, input and output, flags, and program memory.
16.1Program mode and how lines are recorded#
Shift R/S turns PRGM mode on or off. In PRGM mode keys are not executed; they are recorded as numbered program lines. The display shows the current line and the next line, for example 01▸LBL "CIRC". Line 00 is a header showing the size of the current program. Memory holds any number of programs one after another: each ends with END, and the last with .END., which marks the end of memory.


Numbers are recorded as typed. Two numbers in a row need ENTER between them. Press ← to delete the current line and ▲ / ▼ to move through the program. Shift ▲ and shift ▼ (BST and SST) also step through lines.
Record and read a program
Turn on PRGM mode and record a label, then x squared, then pi, then multiply and return.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERΣ+√x1/xLOGLNΣ+Σ+√xENTER⇧x²√x⇧πR↓×⇧PGM.FCN31/x
Press EXIT to close the menu, then up twice to move back through the lines.
EXIT▲▲

03▸Step back with BST
Record the three lines 1, ENTER, 2.
⇧PRGMR/S1ENTER2⇧PRGMR/SEXITEXITTurn on PRGM mode and press down three times to reach the last line, then shift up (BST) once to go back one line.
⇧PRGMR/S▼▼▼⇧BST▲

ENTER16.3Write and run a program#
A global label has a name such as "CIRC", typed in ALPHA. Run it with XEQ and the name, or press XEQ and choose it from the menu. A program continues until RTN. Local labels are two-digit numbers used inside a program.
Circle area program
Record CIRC: label, square, pi, multiply, return.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERΣ+√x1/xLOGLNΣ+Σ+√xENTER⇧x²√x⇧πR↓×⇧PGM.FCN31/x⇧PRGMR/SEXITEXIT
Run it with radius 5: XEQ, then the name.
5XEQ⇧ALPHAENTERΣ+√x1/xLOGLNΣ+Σ+√xENTER

78.5398Hypotenuse from two legs
Record HYP: square, swap, square, add, square root. (EXIT closes the PGM.FCN menu so that the square-root key is not read as a menu key.)
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTER1/x√xXEQ√xLOG√xENTER⇧x²√xx⇄y⇧x²√x+EXIT√x⇧PGM.FCN31/x⇧PRGMR/SEXITEXITEnter 3 and 4 and run it.
3ENTER4XEQ⇧ALPHAENTER1/x√xXEQ√xLOG√xENTER

5.0000Choose the program from the XEQ menu
Record CIRC, then press XEQ and the first menu key.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERΣ+√x1/xLOGLNΣ+Σ+√xENTER⇧x²√x⇧πR↓×⇧PGM.FCN31/x⇧PRGMR/SEXITEXIT5XEQΣ+

78.5398Running from the CATALOG
Open CATALOG, PGM, and press the program name.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERΣ+√x1/xLOGLNΣ+Σ+√xENTER⇧x²√x⇧πR↓×⇧PGM.FCN31/x⇧PRGMR/SEXITEXIT2⇧CATALOG+1/xΣ+

12.5664See also Record a keystroke programNamed programs with variables
16.4Loops with DSE and ISG#
DSE and ISG use a control number of the form : the counter, a final value and an increment. ISG adds the increment; DSE subtracts it. After the change, if the counter has passed the final value, the next program line is skipped. This is how a loop ends.
The program below sums the numbers from N down to 1. It stores N in register 00 and a running total in register 01.
- LBL "SUMN"
- STO 00
- 0
- STO 01
- LBL 01
- RCL 00
- STO+ 01
- DSE 00
- GTO 01
- RCL 01
- RTN
Sum 1 to 5
Record SUMN, then run it with 5.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERLN1/xLNLOG√xLOGLOGΣ+ENTERSTO000STO01⇧PGM.FCN3Σ+01RCL00STO+01⇧PGM.FCN3▼XEQ00⇧GTOXEQ01RCL01⇧PGM.FCN31/x⇧PRGMR/SEXITEXIT5XEQ⇧ALPHAENTERLN1/xLNLOG√xLOGLOGΣ+ENTER

15.0000Sum 1 to 10
The same program with 10.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERLN1/xLNLOG√xLOGLOGΣ+ENTERSTO000STO01⇧PGM.FCN3Σ+01RCL00STO+01⇧PGM.FCN3▼XEQ00⇧GTOXEQ01RCL01⇧PGM.FCN31/x⇧PRGMR/SEXITEXIT10XEQ⇧ALPHAENTERLN1/xLNLOG√xLOGLOGΣ+ENTER

55.000016.5Decisions with tests#
A test line (such as X<0?) makes the next line run only if the test is true. If it is false, the next line is skipped. The test menus are X?0 and X?Y on PGM.FCN page 2. Each has six comparisons: =, ≠, <, >, ≤, ≥.

Absolute value with a test
Record AV: if X < 0 then change its sign.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERΣ+Σ+LNLNENTER⇧PGM.FCN3▼Σ+√x+/−⇧PGM.FCN31/x⇧PRGMR/SEXITEXITTry it on −4.
4+/−XEQ⇧ALPHAENTERΣ+Σ+LNLNENTER

4.0000Test from the keyboard
From the keyboard a test answers Yes or No: is 5 less than 3? (Y=5, X=3, X<Y? is the third key of X?Y).
5ENTER3⇧PGM.FCN3▼1/x√x

Yes16.6Subroutines and local labels#
XEQ with a two-digit number calls a local label in the same program; RTN returns to the line after the call. GTO with a label jumps without returning. GTO then . and three digits moves the pointer to a line number; GTO . . goes to the end.
Call a local subroutine
Record SB: call 05, add 1, return; label 05 multiplies by 10.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERLN1/xΣ+1/xENTERXEQ051+⇧PGM.FCN31/x⇧PGM.FCN3Σ+0510×⇧PGM.FCN31/x⇧PRGMR/SEXITEXITRun with 3: (3 × 10) + 1.
3XEQ⇧ALPHAENTERLN1/xΣ+1/xENTER

31.000016.7Ask for input and show results#
INPUT asks for a variable: the screen shows the name and its current value, for example R?0.0000. Type the value and press R/S to continue. VIEW shows name=value. AVIEW shows text from the ALPHA register. PROMPT shows the ALPHA text and stops; press R/S to continue.
Ask for a radius
Record IN: INPUT R, then compute the circle area.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTER1/xLOGLOGΣ+ENTER⇧PGM.FCN3√x⇧ALPHAENTERLNΣ+ENTERRCL⇧ALPHAENTERLNΣ+ENTER⇧x²√x⇧πR↓×⇧PGM.FCN31/x⇧PRGMR/SEXITEXITRun it: the program stops and asks for R.
XEQ⇧ALPHAENTER1/xLOGLOGΣ+ENTER
Type 2 and press R/S.
2R/S

12.5664Show a variable
Record VW: store 42 in Z and VIEW it.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERLNLNXEQΣ+ENTER42STO⇧ALPHAENTERXEQLOGENTER⇧PGM.FCN3LOG⇧ALPHAENTERXEQLOGENTER⇧PGM.FCN31/x⇧PRGMR/SEXITEXITRun it.
XEQ⇧ALPHAENTERLNLNXEQΣ+ENTER

Z=42.0000Prompt with a message
Record PR: type HELLO in ALPHA, then PROMPT, then 7.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERLOG√xLNΣ+ENTER⇧ALPHAENTER1/x√xΣ+LN√x√x√x√xLOG1/xENTER⇧PGM.FCN3▼√x7⇧PRGMR/SEXITEXITRun it; it shows HELLO and waits.
XEQ⇧ALPHAENTERLOG√xLNΣ+ENTER
Press R/S to continue.
R/S

x: 7.0000Show text with AVIEW
Record AW: HELLO text then AVIEW.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERΣ+Σ+XEQΣ+ENTER⇧ALPHAENTERLOG1/x√x1/xENTER⇧PGM.FCN3LN⇧PRGMR/SEXITEXITXEQ⇧ALPHAENTERΣ+Σ+XEQΣ+ENTER

OKARCL adds a value to the end of the ALPHA text, formatted as the display shows it. In ALPHA mode press shift RCL (ARCL) and choose a register, a variable or (with .) a stack register. A text line that starts with ├ adds its text to ALPHA instead of replacing it; type it in a pasted listing as ├"text". ALPHA keeps the last 44 characters.
Label a result with ARCL
Record AR: square X, then ALPHA with the letter R, ARCL ST X (shift RCL, point, X) and AVIEW.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERΣ+Σ+LNΣ+ENTER⇧x²√x⇧ALPHAENTERLNΣ+⇧%RCL.1/x⇧PGM.FCN3LN⇧PRGMR/SEXITEXITRun it with 12.
12XEQ⇧ALPHAENTERΣ+Σ+LNΣ+ENTER

R144.000016.8Indirect addressing with IND#
With IND, the register, variable or stack register you name holds the address to use. If R01 holds 5, then STO IND 01 stores in R05 and RCL IND 01 recalls R05. XEQ IND and GTO IND go to the local label whose number is held there, and FIX, SF, CF and the flag tests accept IND as well. At the prompt press shift . to add IND, then the register number, a name from the menu, or . and a stack register (IND ST X).
Store and recall through a pointer
Put the address 5 in R01. Store 42 through it: STO, shift point, 01.
5STO0142STO⇧SHOW.01Recall R05 directly: it holds 42.
RCL05

x: 42.0000Walk through registers in a loop
Store 1, 2 and 3 in R05 to R07. Record SM: a counter 5.007 in R00, a sum in R01, and a loop that adds RCL IND 00.
1STO052STO063STO07⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERLN1/x√xLOGENTER5.007STO000STO01⇧PGM.FCN3Σ+01RCL⇧SHOW.00STO+01⇧PGM.FCN3▼LN00⇧GTOXEQ01RCL01⇧PGM.FCN31/x⇧PRGMR/SEXITEXITRun it: 1 + 2 + 3.
XEQ⇧ALPHAENTERLN1/x√xLOGENTER

x: 6.000016.9Flags in a program#
Set a flag and branch on it
Record FL: set flag 01, then if it is set run the next line (100).
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTER1/xΣ+√x√xENTER⇧FLAGS6Σ+01⇧FLAGS6√x01100⇧PRGMR/SEXITEXITRun it.
XEQ⇧ALPHAENTER1/xΣ+√x√xENTER

100.000016.10Stop, step and interrupt#
Press R/S in PRGM mode to record a STOP line. When it runs, the program stops there and R/S resumes it. Outside PRGM mode, shift ▼ (SST) runs one program line at a time. A program that loops forever stops itself with the message Interrupted after about a million steps.
Stop and resume
Record ST: double X, stop, then add 3.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERLN1/xLN√xENTER2×R/S3+⇧PRGMR/SEXITEXITRun it with 5. It stops with 10 in X.
5XEQ⇧ALPHAENTERLN1/xLN√xENTER
Press R/S to resume: 13.
R/S

13.0000Run one line at a time with SST
Record SQ: label, then x squared.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERLN1/xLOGLOGENTER⇧x²√x⇧PRGMR/SEXITEXITType 7, go to the label with GTO and its name, and press shift down (SST) twice: the label is skipped and then x squared runs.
7⇧GTOXEQ⇧ALPHAENTERLN1/xLOGLOGENTER⇧SST▼⇧SST▼

49.0000An endless loop is interrupted
Record IL: label 01 then GTO 01.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTER1/xLOG√x√xENTER⇧PGM.FCN3Σ+01⇧GTOXEQ01⇧PRGMR/SEXITEXITRun it.
XEQ⇧ALPHAENTER1/xLOG√x√xENTER

Interrupted16.11Separate programs: END and GTO . .#
Shift XEQ (GTO), then . twice (GTO . .) moves to a new, empty program after the last one, so the next lines you record start a program of their own. END from CATALOG ▸ FCN ends the program at the current line. Global labels ("NAME") can be reached from any program; local labels (00 to 99) only inside their own program, so two programs can both use LBL 01. Running into END returns like RTN.
Start a new program
Record CIRC, then press GTO . . and turn on PRGM mode: the new program is empty.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERΣ+√x1/xLOGLNΣ+Σ+√xENTER⇧x²√x⇧πR↓×⇧PGM.FCN31/x⇧PRGMR/SEXITEXIT⇧GTOXEQ..⇧PRGMR/S

{ 0-Step Prgm }16.12Delete a program#
Use CLP in the CLEAR menu (second key) and choose the label name. It removes the whole program that holds the label, from its first line to its END. Deleting a single line in PRGM mode is done with ←.
Delete a program by name
Record CIRC, then CLEAR, CLP and its name.
⇧PRGMR/S⇧PGM.FCN3Σ+⇧ALPHAENTERΣ+√x1/xLOGLNΣ+Σ+√xENTER⇧x²√x⇧πR↓×⇧PGM.FCN31/x⇧PRGMR/SEXITEXIT⇧CLEAR←1/xΣ+Try to run it: the label is gone.
EXIT5XEQ⇧ALPHAENTERΣ+√x1/xLOGLNΣ+Σ+√xENTER

Label Not Found16.13Read and paste a program listing#
The Data and programs sheet shows the program memory as a numbered listing with one instruction per line, for example:
- 01 LBL "CIRC"
- 02 X↑2
- 03 PI
- 04 ×
- 05 RTN
Each program in memory is its own listing. You can copy one, or paste a listing: a program whose first global label is already in memory replaces it, and any other is added after the last program (END lines in a pasted listing separate programs). Lines it cannot read are reported so you can fix them.
See also Import and export programs
HP-42S is a trademark of HP Inc.. Trident Calculator is an independent product by South View Studios and is not affiliated with, sponsored by or endorsed by HP. The name is used only to describe the kind of calculator this model resembles; Trident's names, keys, display, fonts and software are its own clean-room design.

