code wiki / _hdl_build / nx_t_vardidx.nx

nx_t_vardidx.nx source

↩ module page · 17 lines · 718 B

1// nx_t_vardidx.nx -- isolate VARIABLE-INDEX byte store (the last suspect). 2// t[0]='6' (constant index, known-good) and t[k]='7' with k a runtime variable. 3// Expect "67". If the 2nd char is wrong/missing, nxasm mis-encodes the 4// register-indirect / variable-index byte store. No loop, no division. ORIGINAL 5import "nx_syscalls.nx" 6 7func main() -> i64 { 8 let p: *i64 = sys_mmap(8) as *i64 9 p[0] = 1 10 var k: i64 = p[0] // runtime 1 (not foldable) 11 let t: *u8 = sys_mmap(8) 12 t[0] = 54 as u8 // '6' at constant index 13 t[k] = 55 as u8 // '7' at VARIABLE index k=1 14 sys_write(1, t, 2) // expect "67" 15 sys_write(1, "\n" as *u8, 1) 16 sys_exit(0); return 0 17}