code wiki / (root) / nx_x86_64_branch_test.nx

nx_x86_64_branch_test.nx

buildroot/runtime/nx_x86_64_branch_test.nx

3660 B110 linesdepth 4pulls 5 transitivereach 0 importersview sourcekind gate/prooftopic x86
docsdependenciesstructsconstsfunctions

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

syscalls.nx nx_outbuf.nx nx_x86_64.nx nx_x86_64_branch_test.nx

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

main out_new sys_mmap out_str out_char x86_emit_function_start x86_emit_section_text out_str ↻ out_str ↻ out_char ↻ x86_emit_label out_str ↻ out_char ↻ x86_emit_movabsq out_str ↻ out_i64 out_char ↻ sys_mmap ↻ out_char ↻ x86_emit_syscall out_str ↻ x86_emit_function_end out_str ↻ out_char ↻ x86_emit_prologue x86_round_up_16 out_str ↻ out_i64 ↻ x86_emit_cmpq_rr out_str ↻ out_char ↻ x86_emit_setcc out_str ↻ x86_cc_suffix out_char ↻ x86_emit_movzbq_rr out_str ↻ out_char ↻ x86_emit_testq_rr out_str ↻

structs

none

consts

none

functions

37func emit_write_byte(o: *OutBuf, ch: i64, scratch_disp: i64) -> i64
49func main() -> i64