code wiki / _hdl_build / _hex_authored.nx

_hex_authored.nx source

↩ module page · 15 lines · 725 B

1// AUTHORED BY THE NISHI BUILDER (hex template) -- lowercase hex encode, bits-up 2import "nx_syscalls.nx" 3func hex_encode(b: *u8, n: i64, out: *u8) -> i64 { 4 let dig: *u8="0123456789abcdef" as *u8; var op: i64=0; var i: i64=0 5 while i<n { let v: i64=b[i] as i64; out[op]=dig[(v>>4)&0x0f]; op=op+1; out[op]=dig[v&0x0f]; op=op+1; i=i+1 } 6 return op 7} 8func main() -> i64 { 9 let b: *u8=sys_mmap(8); b[0]=0xDE as u8; b[1]=0xAD as u8; b[2]=0xBE as u8; b[3]=0xEF as u8 10 let out: *u8=sys_mmap(32); let n: i64=hex_encode(b, 4, out) 11 let exp: *u8="deadbeef" as *u8 12 var ok: i64=1; if n!=8 { ok=0 } var i: i64=0; while i<8 { if out[i]!=exp[i] { ok=0 } i=i+1 } 13 if ok==1 { sys_exit(0) } sys_exit(1) 14 return 1 15}