-
Notifications
You must be signed in to change notification settings - Fork 1
/
fizzbuzz.wala
47 lines (44 loc) · 962 Bytes
/
fizzbuzz.wala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
memory(export("memory") 1)
data((64) "Fizz Buzz ")
func export("_start")
local $n u32
{$BUF := 32u32}
{$DATA := 64u32}
{$n = 1}
loop
if {$n % 15}
if {$n % 5}
if {$n % 3}
then
;; itoa 2 digit
*= $BUF
if (result u32) {$n >= 10}
{{$n / 10} + 0x30}
else 0
*= $BUF offset=1
u8 {{$n % 10} + 0x30}
{$BUF *= offset=2 0x20u8} ;; space
$puts($BUF 3)
$puts($DATA 5)
$puts({$DATA + 5} 5)
$puts($DATA 10)
{$n = {$n + 1}}
br_if 0 {$n <= 100}
{$BUF *= 0xAu8} ;; \n
$puts($BUF 1)
import "wasi_unstable" "fd_write"
func $fd_write
param i32 i32 i32 i32
result i32
func $puts
param $ptr i32
param $len i32
{$CIO := 8}
{$CIO *= $ptr}
{$CIO *= offset=4 $len}
$fd_write
1 ;; fd: stdout
$CIO ;; const ciovec*
1 ;; len of ciovec
4 ;; written*
drop