code wiki / _hdl_build / nx_t_miniloop.nx
nx_t_miniloop.nx source
↩ module page · 15 lines · 548 B
1// nx_t_miniloop.nx -- minimal while-loop probe. s = 0+1+2 = 3, printed as one char,
2// NO second loop, NO idiv. Expect "3". If nxasm prints wrong/empty, the defect is
3// basic while-loop codegen (backward conditional branch / loop-carried var). ORIGINAL
4import "nx_syscalls.nx"
5
6func main() -> i64 {
7 var i: i64 = 0
8 var s: i64 = 0
9 while i < 3 { s = s + i; i = i + 1 } // s = 3
10 let b: *u8 = sys_mmap(8)
11 b[0] = (48 + s) as u8 // expect '3'
12 b[1] = 10 as u8
13 sys_write(1, b, 2)
14 sys_exit(0); return 0
15}