code wiki / _hdl_build / nx_constidx_ctrl.nx
nx_constidx_ctrl.nx source
↩ module page · 28 lines · 742 B
1// nx_constidx_ctrl.nx -- CONTROL for nx_constidx_probe.nx. Byte-identical EXCEPT the const literal is copied
2// into a LOCAL let before indexing. This is the ONLY variable between the two files.
3// license_tier: ORIGINAL No hw writes (Rule 26).
4import "nx_syscalls.nx"
5
6const CP_S: *u8 = "abc" as *u8
7const CP_N: i64 = 3
8
9func cp_sum() -> i64 {
10 let s: *u8 = CP_S
11 var t: i64 = 0
12 var i: i64 = 0
13 while i < CP_N {
14 t = t + (s[i] as i64)
15 i = i + 1
16 }
17 return t
18}
19
20func main(argc: i64, argv: *i64) -> i64 {
21 let v: i64 = cp_sum()
22 if v == 294 {
23 sys_write(1, "CONSTIDX-CTRL ok sum=294\n" as *u8, 25)
24 return 0
25 }
26 sys_write(1, "CONSTIDX-CTRL WRONG-SUM\n" as *u8, 23)
27 return 1
28}