Added fizzbuzz example
This commit is contained in:
parent
d6ef361383
commit
557584819f
|
@ -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
|
Loading…
Reference in New Issue