Added fizzbuzz example

This commit is contained in:
neauoire 2021-10-12 18:38:45 -07:00
parent d6ef361383
commit 557584819f
1 changed files with 43 additions and 0 deletions

View File

@ -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