Reference Guide

2
RPL Programming Examples 2-1
2.RPL Programming Examples
The programs in this chapter demonstrate basic programming concepts. These programs are intended to improve
your programming skills, and to provide supplementary functions for your calculator.
At the end of each program, the program’s checksum and size in bytes are listed to help make sure you typed the
program in correctly. (The checksum is a binary integer that uniquely identifies the program based on its contents).
To make sure you’ve keyed the program in correctly, store it in its name, put the name in level 1, then execute the
BYTES command (
#MEM#
%BYTES%
). This returns the program’s checksum to level 2, and its size in bytes
to level 1. (If you execute BYTES with the program object in level 1, you’ll get a different byte count.)
The examples in this chapter assume the calculator is in its initial, default condition — they assume you haven’t
changed any of the calculator’s operating modes, with the exception of selecting RPN mode. (To reset the calculator
to this condition, see “Memory Reset” in chapter 5 of the HP 48G Series User's Guide.)
Each program listing in this chapter gives the following information:
A brief description of the program.
A syntax diagram (where needed) showing the program’s required inputs and resulting outputs.
Discussion of special programming techniques in the program.
Any other programs needed.
The program listing.
The program’s checksum and byte size.
Fibonacci Numbers
This section includes three programs that calculate Fibonacci numbers:
FIB1 is a user-defined function that is defined recursively (that is, its defining procedure contains its own name).
FIB1 is short.
FIB2 is a user-defined function with a definite loop. It’s longer and more complicated than FIB1, but faster.
FIBT calls both FIB1 and FIB2 and calculates the execution time of each subprogram.
FIB1 and FIB2 demonstrate an approach to calculating the nth Fibonacci number F
n
, where:
F
0
= 0, F
1
= 1, F
n
= F
n-1
+ F
n-2
FIB1 (Fibonacci Numbers, Recursive Version)
Level 1
Level 1
n
F
n