code wiki / (root) / smoke_nxasm_demo2.nx

smoke_nxasm_demo2.nx source

↩ module page · 16 lines · 958 B

1// Same as smoke_nxasm_demo.nx but with the full directive header 2// nxc2 emits. Expect 72 still (directives don't emit code). 3import "syscalls.nx" 4import "nxasm_v2.nx" 5 6func main() -> i64 { 7 let s: *u8 = "# Auto-generated\n .option nopic\n .attribute arch, \"rv64i2p1_m2p0\"\n .attribute unaligned_access, 0\n .attribute stack_align, 16\n\n .text\n .globl main\n .type main, @function\nmain:\n addi sp, sp, -48\n sd ra, 40(sp)\n li a0, 30\n li a7, 93\n ecall\n ld ra, 40(sp)\n addi sp, sp, 48\n ret\n .size main, .-main\n" 8 var sl: i64 = 0 9 while s[sl] != 0 { sl = sl + 1 } 10 let out: *u8 = alloc(512) 11 let n: i64 = assemble(s, sl, out, 512) 12 if n == -1 { return __syscall(93, 200, 0, 0, 0, 0, 0) } 13 if n == -2 { return __syscall(93, 201, 0, 0, 0, 0, 0) } 14 if n == -3 { return __syscall(93, 202, 0, 0, 0, 0, 0) } 15 return __syscall(93, n & 0xFF, 0, 0, 0, 0, 0) 16}