nx_x86_64_branch_test.nx
buildroot/runtime/nx_x86_64_branch_test.nx
about
nx_x86_64_branch_test.nx -- session 3 smoke for cmp/setcc/branch.
Builds a program that exercises every cmp/branch primitive:
rax := 5
rcx := 5
cmpq %rcx, %rax ; rax - rcx == 0
sete %al ; al = 1
movzbq %al, %rax ; rax = 1
testq %rax, %rax ; flags from rax (non-zero)
jne .Leq ; branch taken
write 'N' and exit (should NOT reach)
.Leq:
write 'Y' (means: equality compare worked)
rax := 3
rcx := 7
cmpq %rcx, %rax ; rax - rcx == -4 < 0
jl .Llt ; signed less-than (cmpq operand order:
; AT&T `cmpq src1, src2` is src2 - src1,
; so jl jumps when src2 < src1 -- here
; rax (3) < rcx (7) yes)
write 'B' and exit (should NOT reach)
.Llt:
write 'L' (means: signed-less-than branch worked)
jmp .Ldone
.Ldone:
exit 0
Expected stdout: "YL" (2 bytes hex 59 4C).
dependencies 3 imports · 0 importers
imports: syscalls.nxnx_outbuf.nxnx_x86_64.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| none |
functions
| 37 | func emit_write_byte(o: *OutBuf, ch: i64, scratch_disp: i64) -> i64 |
| 49 | func main() -> i64 |