Reference Guide
RPL Programming Examples 2-3
FIB2 program listing
Program: Comments:
«
→ n
«
Creates a local variable structure.
IF n 1 ‰
If n
≤
1,
THEN n
then F
n
= n;
ELSE
otherwise …
0 1
Puts F
0
and F
1
on the stack.
2 n
START
From 2 to n does the following loop:
DUP
Copies the latest F (initially F
1
)
ROT
Gets the previous F (initially F
0
)
+
Calculates the next F (initially F
2
)
NEXT
Repeats the loop.
SWAP DROP
Drops F
n-1
.
END
Ends the ELSE clause.
»
Ends the defining procedure.
»
`O
FIB2 K
Stores the program in FIB2.
Checksum: # 23902d (press O
%FIB2%
!°
#MEM#
%BYTES%
)
Bytes: 89
Example:
Calculate F
6
and F
10
.
Calculate F
6
.
J
6
%FIB2%
Calculate F
10
.
10
%FIB2%