code wiki / _hdl_build / nx_g_pn_lite_lib.nx
nx_g_pn_lite_lib.nx source
↩ module page · 14 lines · 674 B
1// nx_g_pn_lite_lib.nx -- single-responsibility g_pn LITE variant (no negative-number branch).
2// This is the SUBSET body that nx_g_pn_lib's superset self-check refuses; files carrying it delegate HERE
3// (behavior-identical for their non-negative usage - the ONLY difference is negatives, which gate counts never are).
4// license_tier: ORIGINAL
5import "nx_syscalls.nx"
6func g_pn(v: i64) -> i64 {
7 let b: *u8 = sys_mmap(28); var x: i64 = v
8 if x == 0 { b[0]=48; sys_write(1,b,1); return 0 }
9 var d: i64=0; var y: i64=x
10 while y>0 { d=d+1; y=y/10 }
11 var i: i64=d-1; y=x
12 while i>=0 { b[i]=(48+(y%10)) as u8; y=y/10; i=i-1 }
13 sys_write(1,b,d); return 0
14}