| ... | ... |
@@ -1,5 +1,5 @@ |
| 1 | 1 |
( Fibonacci: |
| 2 |
- A series of numbers where the next number |
|
| 2 |
+ A series of numbers where the next number |
|
| 3 | 3 |
is made of the two numbers before it ) |
| 4 | 4 |
|
| 5 | 5 |
|100 |
| ... | ... |
@@ -7,13 +7,16 @@ |
| 7 | 7 |
#0019 #0000 |
| 8 | 8 |
&l |
| 9 | 9 |
DUP2 pdec #2018 DEO |
| 10 |
- DUP2 fib pdec #0a18 DEO |
|
| 10 |
+ DUP2 fib pdec #2018 DEO |
|
| 11 |
+ DUP2 #0000 #0001 ROT2 fibr pdec #0a18 DEO POP2 POP2 |
|
| 11 | 12 |
INC2 GTH2k ?&l |
| 12 | 13 |
POP2 POP2 |
| 13 | 14 |
#010f DEO |
| 14 | 15 |
|
| 15 | 16 |
BRK |
| 16 | 17 |
|
| 18 |
+( recursive ) |
|
| 19 |
+ |
|
| 17 | 20 |
@fib ( num -- numfib* ) |
| 18 | 21 |
#0001 GTH2k ?&ok |
| 19 | 22 |
POP2 JMP2r &ok |
| ... | ... |
@@ -22,6 +25,19 @@ BRK |
| 22 | 25 |
ADD2 |
| 23 | 26 |
JMP2r |
| 24 | 27 |
|
| 28 |
+( tail-recursive ) |
|
| 29 |
+ |
|
| 30 |
+@fibr ( a* b* num* -- a* b* num* ) |
|
| 31 |
+ ORAk ?&no-0 |
|
| 32 |
+ POP2 OVR2 JMP2r &no-0 |
|
| 33 |
+ DUP2 #0001 NEQ2 ?&no-1 |
|
| 34 |
+ POP2 DUP2 JMP2r &no-1 |
|
| 35 |
+ #0001 SUB2 STH2 |
|
| 36 |
+ SWP2 ADD2k NIP2 STH2r |
|
| 37 |
+!fibr |
|
| 38 |
+ |
|
| 39 |
+( print routine ) |
|
| 40 |
+ |
|
| 25 | 41 |
@pdec ( short* -- ) |
| 26 | 42 |
|
| 27 | 43 |
#2710 LIT2r 00fb |