RPN Calculator Programming Guide
This calculator supports keystroke programming, allowing you to store and automate complex sequences of operations. This guide explains how to create, edit, and run programs.
Basic Concepts
- Keystroke Programming: You “record” a sequence of key presses into a program memory slot. When you run the program, the calculator executes those key presses automatically.
- Labels: Programs are stored under numeric labels from
00
to 99
. This allows you to have up to 100 different programs.
- Program Counter (PC): This is a pointer to the current step in a program. When editing, it shows where the next instruction will be recorded. When running, it points to the instruction being executed.
Creating and Editing Programs
Entering and Exiting Program Mode
The P/R
key (f-shift R/S
) is the master key for programming.
Recording and Editing Instructions
Recording and Editing Instructions
Once in program mode, the display changes to show the program listing.
- Recording: Simply press the keys you want to record. Each key press is added as a step, and the program counter (
>
) advances automatically.
- Navigating: Use the dedicated
▲
and ▼
keys on the virtual keyboard to move the program counter without recording new steps. This allows you to view or edit your program.
- Overwriting: To change an instruction, navigate to it using
▲
/▼
and press the new key you want. The old instruction will be replaced.
- Deleting: Navigate to the instruction you want to remove and press
<-
(Backspace). Subsequent instructions will shift up.
- Clearing a Program: While in program mode, press
CLA
to delete all instructions in the current program.
- Inserting: Navigate to the position where you want to insert a new step and press
<+
(f-shift <-
). This inserts a blank line and shifts subsequent instructions down. You can then enter the new instruction on the blank line.
Running Programs
The R/S
key is used to run programs and to pause/resume them.
Program Control Instructions
You can use special instructions within your programs to control their flow.
Pause and Resume (R/S
)
Placing an R/S
instruction in your program will cause it to pause execution at that point. This is useful for programs that need to stop for user input. To resume the program from where it paused, simply press R/S
again.
Note: A program automatically stops at its last instruction, leaving the result on the stack. An R/S
at the very end is not necessary unless you want to explicitly show a “PAUSED” state.
Unconditional Branching (GTO
)
The GTO
(Go To) instruction causes the program to jump to a different label and continue execution from there.
- Usage:
GTO
, 0
, 1
will jump to the beginning of the program at LBL 01.
Subroutines (GSB
and RTN
)
GSB
(Go to Subroutine) works like GTO
, but it remembers where it came from.
RTN
(Return) tells the program to go back to the instruction right after the GSB
call that sent it to the subroutine. This is essential for creating reusable pieces of code.
Conditional Skips
Conditional instructions test the value in the X register (or X and Y registers).
- If the condition is true: The very next instruction is executed.
- If the condition is false: The very next instruction is skipped.
Note: These conditional tests are non-destructive. They check the values in the X and Y registers without changing them or dropping the stack.
Available conditions include: x>0?
, x=0?
, x!=0?
, x<=y?
, x=y?
, x!=y?
.
Flags (SF
, CF
, F?
)
The calculator has 10 flags (0-9) that you can turn on or off to store simple yes/no state.
SF
(Set Flag): SF
, 1
turns Flag 1 ON.
CF
(Clear Flag): CF
, 1
turns Flag 1 OFF.
F?
(Test Flag): F?
, 1
checks if Flag 1 is ON. If it is, the next instruction runs. If it’s OFF, the next instruction is skipped.
Using Programs with SOLVE, INTEG, DERIV
The SOLVE
, INTEG
(Integrate), and DERIV
(Derivative) functions all operate on user-written programs. This is one of the most powerful features of the calculator.
When you use one of these functions, you provide the label of a program that defines your mathematical function, f(x)
. The calculator then calls your program repeatedly to find the solution.
Your program’s responsibility is simple:
- It should assume the input value,
x
, is in the X register when it starts.
- It should perform its calculations on the real part of the number. The solver, integrator, and derivative functions do not support complex numbers.
- It must leave the final result,
f(x)
, in the X register before it ends (with RTN
or by reaching the last step).
The program should not consume extra items from the stack, as the solver does not provide them. It should only use the initial value in X.
Example: A program to calculate f(x) = x³ - 2x + 5
for the solver would look like this:
Program (LBL 20):
STO 00
(Store x)
x²
RCL 00
*
(x³)
2
RCL 00
*
(2x)
-
(x³ - 2x)
5
+
(x³ - 2x + 5)
RTN
Saving and Loading
Your programs are automatically saved to a file named programs.rpn
when you exit the calculator application. They are automatically loaded the next time you start it, so your work is always preserved.
Programming Examples
Example 1: Area of a Circle
This program will take a radius from the stack, calculate the area (π * r²), and pause to display the result.
Program (LBL 01):
- Enter Program Mode:
P/R
, ENTER
(or 0
, 1
if it’s the first program)
- Record the steps:
x²
, π
, *
- Exit Program Mode:
P/R
To Run:
- Enter the radius:
5
, ENTER
- Run the program:
R/S
, 0
, 1
- Result: The program will end with the area,
78.5398
, in the X register.
Example 2: Sum of Integers from 1 to N
This program calculates the sum of all integers from 1 up to a number N provided on the stack. It demonstrates a loop using GSB
and GTO
.
Program (LBL 10 - Main Routine):
- Enter Program Mode:
P/R
, 1
, 0
- Record the steps:
0
(Initialize sum in X, pushes N to Y)
SWAP
(Put counter N in X, sum in Y)
GSB
, 1
, 1
(Call the loop in LBL 11)
- Exit Program Mode:
P/R
Program (LBL 11 - Loop):
- Enter Program Mode:
P/R
, 1
, 1
- Record the steps:
STO 00
(Temporarily store counter N)
+
(Add counter to the running sum)
RCL 00
(Recall counter)
1
, -
(Decrement counter)
x>0?
(Is the counter still > 0?)
GTO
, 1
, 1
(If yes, loop again)
DROP
(Drop the final counter (0) from X)
RTN
(Return, leaving sum in X)
- Exit Program Mode:
P/R
To Run:
- Enter the number N:
10
, ENTER
- Run the main routine:
R/S
, 1
, 0
- Result:
55
will be in the X register.
Example 3: Factorial (n!)
This program calculates the factorial of a number N. It uses a loop and a temporary memory register.
Program (LBL 12 - Main):
- Enter Program Mode:
P/R
, 1
, 2
- Record:
1
, SWAP
, GSB
, 1
, 3
Program (LBL 13 - Loop):
- Enter Program Mode:
P/R
, 1
, 3
- Record:
STO 00
, *
, RCL 00
, 1
, -
, x>0?
, GTO
, 1
, 3
, DROP
, RTN
To Run:
- Enter N:
5
, ENTER
- Run:
R/S
, 1
, 2
- Result:
120
will be in the X register.
Example 4: Quadratic Formula
This program solves for the roots of ax² + bx + c = 0
. It calculates both roots and leaves them in the X and Y registers. It correctly handles both real and complex roots automatically.
Setup: First, store your coefficients in memory registers.
- Enter
a
, then STO
, 0
, 0
- Enter
b
, then STO
, 0
, 1
- Enter
c
, then STO
, 0
, 2
Program (LBL 14):
- Enter Program Mode:
P/R
, 1
, 4
- Record:
RCL 01
, x²
(b²)
4
, RCL 00
, *
(4a)
RCL 02
, *
(4ac)
-
(d = b² - 4ac)
STO 03
(store d)
SQRT
(sqrt(d))
RCL 01
, CHS
(-b)
+
(-b + sqrt(d))
2
, RCL 00
, *
(2a)
/
(root 1)
RCL 01
, CHS
(-b)
RCL 03
, SQRT
(sqrt(d))
-
(-b - sqrt(d))
2
, RCL 00
, *
(2a)
/
(root 2)
SWAP
(root 1 in X, root 2 in Y)
- Exit:
P/R
To Run (for x² + 2x + 5 = 0, which has complex roots):
- Store coefficients:
1 STO 00
, 2 STO 01
, 5 STO 02
- Run:
R/S
, 1
, 4
- Result: The program will end. X will contain
-1+2i
and Y will contain -1-2i
.