commit 557584819fa66f8fb376aa7aec5b258849e9be0e
parent d6ef36138393d7cbefff7aac56c35d1447396b8e
Author: neauoire <aliceffekt@gmail.com>
Date: Tue, 12 Oct 2021 18:38:45 -0700
Added fizzbuzz example
Diffstat:
1 file changed, 43 insertions(+), 0 deletions(-)
diff --git a/projects/examples/demos/fizzbuzz.tal b/projects/examples/demos/fizzbuzz.tal
@@ -0,0 +1,43 @@
+( FizzBuzz: a program that prints the integers from 1 to 100.
+ for multiples of three, print "Fizz"
+ for multiples of five, print "Buzz"
+ for multiples of both three and five, print "FizzBuzz" )
+
+%MOD { DIVk MUL SUB }
+%HALT { #01 #0f DEO }
+%EMIT { #18 DEO }
+%RTN { JMP2r }
+
+@program
+
+|0100 ( -> )
+
+ #6400
+ &loop
+ LITr 00
+ DUP #03 MOD ,&no3 JCN ;fizz-txt ;print-str JSR2 INCr &no3
+ DUP #05 MOD ,&no5 JCN ;buzz-txt ;print-str JSR2 INCr &no5
+ STHr ,&resume JCN
+ ( print decimal )
+ DUPk #0a DIV #30 ADD EMIT
+ #0a MOD #30 ADD EMIT
+ &resume
+ ( add linebreak ) #0a EMIT
+ INC GTHk ,&loop JCN
+ POP2
+
+ HALT
+
+BRK
+
+@print-str ( addr* -- )
+
+ &loop
+ LDAk EMIT
+ INC2 LDAk ,&loop JCN
+ POP2
+
+RTN
+
+@fizz-txt "Fizz $1
+@buzz-txt "Buzz $1