(fizzbuzz.tal) Formatting

This commit is contained in:
Devine Lu Linvega 2023-07-21 11:35:56 -07:00
parent 050690181a
commit a673d63336
1 changed files with 22 additions and 26 deletions

View File

@ -1,40 +1,36 @@
( FizzBuzz: ( FizzBuzz: From 1 to 100, for multiples of 3 print "Fizz", of 5 "Buzz" and for both "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" )
|0100 ( -> ) |0100
@on-reset ( -> )
#6400 #6400
&loop &loop ( integer )
( integer ) DUP print-dec #2018 DEO
DUPk print-dec #2018 DEO DUP #03 mod ?&>no-3
( fizzbuzz ) ;dict/fizz print-str &>no-3
DUP #03 mod ?&no3 ;dict/fizz print-str &no3 DUP #05 mod ?&>no-5
DUP #05 mod ?&no5 ;dict/buzz print-str &no5 ;dict/buzz print-str &>no-5
#0a18 DEO #0a18 DEO
INC GTHk ?&loop INC GTHk ?&loop
POP2 POP2
( halt ) ( halt ) #010f DEO
#010f DEO BRK
BRK
@mod ( a b -- c ) @mod ( a b -- c )
DIVk MUL SUB DIVk MUL SUB JMP2r
JMP2r
@print-dec ( num -- ) @print-dec ( num -- )
#0a DIV print-num ( x0 ) DUP #0a DIV print-dec/num
#0a DIVk MUL SUB ( 0x ) #0a DIVk MUL SUB &num #30 ADD #18 DEO
@print-num JMP2r
#30 ADD #18 DEO
JMP2r
@print-str ( addr* -- ) @print-str ( addr* -- )
&while &while ( -- )
LDAk #18 DEO LDAk #18 DEO
INC2 LDAk ?&while INC2 LDAk ?&while
POP2 POP2 JMP2r
JMP2r
@dict ( strings )
&fizz "Fizz $1
&buzz "Buzz $1
@dict &fizz "Fizz $1 &buzz "Buzz $1