uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

fib.tal (818B)


      1 ( Fibonacci: Numbers made of the two numbers before it )
      2 
      3 |0100
      4 
      5 @on-reset
      6 	#0019 #0001
      7 	&l ( -- )
      8 		( index ) DUP2 pdec #2018 DEO
      9 		( recursive ) DUP2 fib pdec #2018 DEO
     10 		( tail-recursive ) DUP2 #0000 #0001 ROT2 fibr pdec
     11 		( lb ) #0a18 DEO
     12 		POP2 POP2 INC2 GTH2k ?&l
     13 	POP2 POP2
     14 	( end ) #800f DEO
     15 	BRK
     16 
     17 (
     18 @|recursive )
     19 
     20 @fib ( num* -- numfib* )
     21 	#0001 GTH2k ?&>ok
     22 		POP2 JMP2r &>ok
     23 	SUB2k fib STH2
     24 	INC2 SUB2 fib STH2r
     25 	ADD2 JMP2r
     26 
     27 (
     28 @|tail-recursive )
     29 
     30 @fibr ( a* b* num* -- a* b* numfib* )
     31 	#0001 NEQ2k ?&>no-1
     32 		POP2 POP2 DUP2 JMP2r &>no-1
     33 	SUB2 STH2
     34 	SWP2 OVR2 ADD2 STH2r !fibr
     35 
     36 (
     37 @|stdlib )
     38 
     39 @pdec ( short* -- )
     40 	#2710 LIT2r 00fb
     41 	&w ( -- )
     42 		DIV2k #000a DIV2k MUL2 SUB2 SWPr EQUk OVR STHkr EQU AND ?&>skip
     43 			DUP LIT "0 ADD #18 DEO
     44 			INCr &>skip
     45 		POP2 #000a DIV2 SWPr INCr STHkr ?&w
     46 	POP2r POP2 POP2 JMP2r
     47