Browse code

(fib.tal) Improved example

Devine Lu Linvega authored on 02/06/2023 04:53:28
Showing 1 changed files
... ...
@@ -2,21 +2,37 @@
2 2
 	A series of numbers where the next number 
3 3
 	is made of the two numbers before it )
4 4
 
5
-|0100 ( -> ) @reset
5
+|100
6 6
 
7
-	#0000 INC2k ADD2k
8
-	&loop
9
-		DUP2 print #0a18 DEO
10
-		ADD2k LTH2k ?&loop
11
-	( halt )
7
+	#0019 #0000
8
+	&l
9
+		DUP2 pdec #2018 DEO
10
+		DUP2 fib pdec #0a18 DEO
11
+		INC2 GTH2k ?&l
12
+	POP2 POP2
12 13
 	#010f DEO
13 14
 
14 15
 BRK
15 16
 
16
-@print ( short* -- )
17
+@fib ( num -- numfib* )
18
+	#0001 GTH2k ?&ok
19
+		POP2 JMP2r &ok
20
+	SUB2k fib STH2 INC2
21
+	SUB2 fib STH2r
22
+		ADD2
23
+JMP2r
24
+
25
+@pdec ( short* -- )
17 26
 
18
-	SWP print/byte
19
-	&byte ( byte -- ) DUP #04 SFT print/char
20
-	&char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
27
+	#2710 LIT2r 00fb
28
+	&w
29
+		DIV2k #000a DIV2k MUL2 SUB2 SWPr
30
+		EQUk OVR STHkr EQU AND ?&skip
31
+			DUP LIT "0 ADD #19 DEO INCr
32
+			&skip
33
+		POP2 #000a DIV2
34
+		SWPr INCr STHkr ?&w
35
+	POP2r POP2 POP2
21 36
 
22 37
 JMP2r
38
+