Browse code

(fizzbuzz.tal) Migrated to immediate opcodes

Devine Lu Linvega authored on 24/02/2023 03:04:34
Showing 1 changed files
... ...
@@ -1,24 +1,22 @@
1
-( FizzBuzz: 
1
+( FizzBuzz:
2 2
 	A program that prints the integers from 1 to 100.
3 3
 	for multiples of three, print "Fizz"
4 4
 	for multiples of five, print "Buzz"
5 5
 	for multiples of both three and five, print "FizzBuzz" )
6 6
 
7
-|0100 ( -> ) @reset
8
-
7
+|0100 ( -> )
9 8
 	#6400
10 9
 	&loop
11 10
 		( integer )
12
-		DUPk ,print-dec JSR #2018 DEO
11
+		DUPk print-dec #2018 DEO
13 12
 		( fizzbuzz )
14
-		DUP #03 ,mod JSR ,&no3 JCN ;s/fizz ,print-str JSR &no3
15
-		DUP #05 ,mod JSR ,&no5 JCN ;s/buzz ,print-str JSR &no5
13
+		DUP #03 mod ?&no3 ;dict/fizz print-str &no3
14
+		DUP #05 mod ?&no5 ;dict/buzz print-str &no5
16 15
 		#0a18 DEO
17
-		INC GTHk ,&loop JCN
16
+		INC GTHk ?&loop
18 17
 	POP2
19 18
 	( halt )
20 19
 	#010f DEO
21
-
22 20
 BRK
23 21
 
24 22
 @mod ( a b -- c )
... ...
@@ -26,17 +24,17 @@ BRK
26 24
 JMP2r
27 25
 
28 26
 @print-dec ( num -- )
29
-	#0a DIV ,&emit JSR
30
-	#0a ,mod JSR
31
-	&emit
27
+	#0a DIV print-num
28
+	#0a DIVk MUL SUB
29
+@print-num
32 30
 	#30 ADD #18 DEO
33 31
 JMP2r
34 32
 
35 33
 @print-str ( addr* -- )
36 34
 	&while
37 35
 		LDAk #18 DEO
38
-		INC2 LDAk ,&while JCN
36
+		INC2 LDAk ?&while
39 37
 	POP2
40 38
 JMP2r
41 39
 
42
-@s &fizz "Fizz $1 &buzz "Buzz $1
40
+@dict &fizz "Fizz $1 &buzz "Buzz $1