code wiki / (root) / smoke_loop.nx

smoke_loop.nx source

↩ module page · 20 lines · 409 B

1// smoke_loop.nx -- exercise a while loop + struct field write inside. 2 3import "syscalls.nx" 4 5struct Counter { 6 n: i64, 7 pos: i64, 8} 9 10func main() -> i64 { 11 let raw: *u8 = sys_mmap(32) 12 let c: *Counter = raw as *Counter 13 c.n = 0 14 c.pos = 0 15 while c.pos < 10 { 16 c.n = c.n + c.pos 17 c.pos = c.pos + 1 18 } 19 return __syscall(93, c.n, 0, 0, 0, 0, 0) 20}