code wiki / _hdl_build / nx_t_loop.nx
nx_t_loop.nx source
↩ module page · 17 lines · 736 B
1// nx_t_loop.nx -- bisect: is the nxasm defect the LOOP or the FUNCTION CALL?
2// Same digit-extraction as pr_n but INLINED into main (a while-loop, but NO
3// separate function call). Prints "42". If this works -> defect is the call/ret/arg
4// ABI; if it fails -> defect is the loop / loop-carried variable. license_tier: ORIGINAL
5import "nx_syscalls.nx"
6
7func main() -> i64 {
8 var m: i64 = 42
9 let t: *u8 = sys_mmap(28); var k: i64 = 0
10 if m == 0 { t[0] = 48 as u8; k = 1 }
11 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
12 let b: *u8 = sys_mmap(28); var i: i64 = 0
13 while i < k { b[i] = t[k - 1 - i]; i = i + 1 }
14 sys_write(1, b, k)
15 sys_write(1, "\n" as *u8, 1)
16 sys_exit(0); return 0
17}