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