(fib.tal) Formatted
This commit is contained in:
parent
0c9e67b9be
commit
98a0c7d609
|
@ -1,54 +1,47 @@
|
||||||
( Fibonacci:
|
( Fibonacci: Numbers made of the two numbers before it )
|
||||||
A series of numbers where the next number
|
|
||||||
is made of the two numbers before it )
|
|
||||||
|
|
||||||
|0100 @on-reset
|
|0100
|
||||||
|
|
||||||
#0019 #0000
|
@on-reset
|
||||||
&l
|
#0019 #0001
|
||||||
DUP2 pdec #2018 DEO
|
&l ( -- )
|
||||||
DUP2 fib pdec #2018 DEO
|
( index ) DUP2 pdec #2018 DEO
|
||||||
DUP2 #0000 #0001 ROT2 fibr pdec #0a18 DEO POP2 POP2
|
( recursive ) DUP2 fib pdec #2018 DEO
|
||||||
INC2 GTH2k ?&l
|
( tail-recursive ) DUP2 #0000 #0001 ROT2 fibr pdec
|
||||||
|
( lb ) #0a18 DEO
|
||||||
|
POP2 POP2 INC2 GTH2k ?&l
|
||||||
POP2 POP2
|
POP2 POP2
|
||||||
#800f DEO
|
( end ) #800f DEO
|
||||||
|
BRK
|
||||||
|
|
||||||
BRK
|
(
|
||||||
|
@|recursive )
|
||||||
( recursive )
|
|
||||||
|
|
||||||
@fib ( num* -- numfib* )
|
@fib ( num* -- numfib* )
|
||||||
#0001 GTH2k ?&ok
|
#0001 GTH2k ?&>ok
|
||||||
POP2 JMP2r &ok
|
POP2 JMP2r &>ok
|
||||||
SUB2k fib STH2 INC2
|
( a ) SUB2k fib STH2
|
||||||
SUB2 fib STH2r
|
( b ) INC2 SUB2 fib STH2r
|
||||||
ADD2
|
( res ) ADD2 JMP2r
|
||||||
JMP2r
|
|
||||||
|
|
||||||
( tail-recursive )
|
(
|
||||||
|
@|tail-recursive )
|
||||||
|
|
||||||
@fibr ( a* b* num* -- a* b* numfib* )
|
@fibr ( a* b* num* -- a* b* numfib* )
|
||||||
ORAk ?&no-0
|
DUP2 #0001 NEQ2 ?&>no-1
|
||||||
POP2 OVR2 JMP2r &no-0
|
POP2 DUP2 JMP2r &>no-1
|
||||||
DUP2 #0001 NEQ2 ?&no-1
|
( a ) #0001 SUB2 STH2
|
||||||
POP2 DUP2 JMP2r &no-1
|
( b ) SWP2 ADD2k NIP2 STH2r !fibr
|
||||||
#0001 SUB2 STH2
|
|
||||||
SWP2 ADD2k NIP2 STH2r
|
|
||||||
!fibr
|
|
||||||
|
|
||||||
( print routine )
|
(
|
||||||
|
@|stdlib )
|
||||||
|
|
||||||
@pdec ( short* -- )
|
@pdec ( short* -- )
|
||||||
|
|
||||||
#2710 LIT2r 00fb
|
#2710 LIT2r 00fb
|
||||||
&w
|
&w ( -- )
|
||||||
DIV2k #000a DIV2k MUL2 SUB2 SWPr
|
DIV2k #000a DIV2k MUL2 SUB2 SWPr EQUk OVR STHkr EQU AND ?&>skip
|
||||||
EQUk OVR STHkr EQU AND ?&skip
|
DUP LIT "0 ADD #18 DEO
|
||||||
DUP LIT "0 ADD #19 DEO INCr
|
INCr &>skip
|
||||||
&skip
|
POP2 #000a DIV2 SWPr INCr STHkr ?&w
|
||||||
POP2 #000a DIV2
|
POP2r POP2 POP2 JMP2r
|
||||||
SWPr INCr STHkr ?&w
|
|
||||||
POP2r POP2 POP2
|
|
||||||
|
|
||||||
JMP2r
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue