code wiki / (root) / _offc_asm_probe.nx

_offc_asm_probe.nx source

↩ module page · 55 lines · 1538 B

1// Diagnostic: read /tmp/probe.s from disk + feed to nxasm_v2. 2 3import "syscalls.nx" 4import "nxasm_v2.nx" 5 6func print_dec(v: i64) -> i64 { 7 let nbuf: *u8 = sys_mmap(32) 8 var n: i64 = v 9 var neg: i64 = 0 10 if n < 0 { neg = 1; n = 0 - n } 11 var k: i64 = 0 12 if n == 0 { nbuf[k] = 0x30; k = 1 } 13 while n > 0 { 14 nbuf[k] = 0x30 + (n - (n / 10) * 10) 15 n = n / 10 16 k = k + 1 17 } 18 if neg == 1 { sys_write(2, "-" as *u8, 1) } 19 var j: i64 = k - 1 20 while j >= 0 { 21 sys_write(2, (((nbuf as i64) + j) as *u8), 1) 22 j = j - 1 23 } 24 return 0 25} 26 27func main() -> i64 { 28 let path: *u8 = "/tmp/probe.s" 29 let fd: i64 = sys_openat_rd(path) 30 if fd < 0 { 31 sys_write(2, "_offc_asm_probe: sys_openat_rd(\"/tmp/probe.s\") returned fd < 0; expected fd >= 0 (file must exist and be readable)\n" as *u8, 117) 32 return 1 33 } 34 let buf: *u8 = sys_mmap(8192) 35 var total: i64 = 0 36 var go: i64 = 1 37 while go == 1 { 38 let tail: *u8 = (((buf as i64) + total) as *u8) 39 let n: i64 = sys_read(fd, tail, 8192 - total) 40 if n <= 0 { go = 0 } 41 if n > 0 { total = total + n } 42 } 43 sys_close(fd) 44 45 sys_write(2, "src bytes=" as *u8, 10) 46 print_dec(total) 47 sys_write(2, "\n" as *u8, 1) 48 49 let out: *u8 = sys_mmap(65536) 50 let r: i64 = assemble(buf, total, out, 65536) 51 sys_write(2, "assemble returned " as *u8, 18) 52 print_dec(r) 53 sys_write(2, "\n" as *u8, 1) 54 return 0 55}