code wiki / _hdl_build / nx_bytes_eq.nx

nx_bytes_eq.nx source

↩ module page · 31 lines · 1641 B

1// nx_bytes_eq.nx -- byte-identity comparator ORGAN (operator 2026-07-02: no shell -- this retires 2// cmp/wc/diff from every lane). usage: nx_bytes_eq <a> <b> 3// Prints sizes + IDENTICAL/first-diff; exit 0 iff byte-identical. The drift-kill primitive for the 4// emitter-organ SSOT doctrine (emit to a compare path, nx_bytes_eq vs the canonical file). 5// license_tier: ORIGINAL 6import "nx_syscalls.nx" 7 8func bw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 9func bn(v: i64) -> i64 { 10 let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} 11 let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} 12 var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } 13 14func main(argc: i64, argv: *i64) -> i64 { 15 if argc < 3 { bw("usage: nx_bytes_eq <a> <b>\n" as *u8); return 2 } 16 let ba: *i64 = sys_mmap(16) as *i64 17 let bb: *i64 = sys_mmap(16) as *i64 18 let a: *u8 = sys_read_file(argv[1] as *u8, ba) 19 let b: *u8 = sys_read_file(argv[2] as *u8, bb) 20 if (a as i64)==0 { bw("BYTES-EQ cannot read a -> RED\n" as *u8); return 1 } 21 if (b as i64)==0 { bw("BYTES-EQ cannot read b -> RED\n" as *u8); return 1 } 22 bw("BYTES-EQ a=" as *u8); bn(ba[0]); bw("B b=" as *u8); bn(bb[0]); bw("B " as *u8) 23 if ba[0] != bb[0] { bw("SIZE-DIFF verdict=RED\n" as *u8); return 1 } 24 var i: i64 = 0 25 while i < ba[0] { 26 if a[i] != b[i] { bw("first_diff=" as *u8); bn(i); bw(" verdict=RED\n" as *u8); return 1 } 27 i = i + 1 28 } 29 bw("IDENTICAL verdict=GREEN\n" as *u8) 30 return 0 31}