From 9dbf42f2138b93987b42069dd3aee4d6fd7917fd Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Sat, 8 Nov 2025 18:50:31 -0800 Subject: implement branch and 0branch; fix jmp_cc_rel_imm8 Force-Push: yes Change-Id: I45c0a5e729cae2493e341ad3b6145708826383ab --- quine.asm | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'quine.asm') diff --git a/quine.asm b/quine.asm index c92f1cd..4eb5017 100644 --- a/quine.asm +++ b/quine.asm @@ -2328,14 +2328,28 @@ cold_start: dq pack_next, lit, 8, packalign, early_here_store dq litstring, "branch", early_create, early_self_codeword, early_here, fetch - ; TODO - dq lit, 8, packalign, early_here_store + ; Save the address we're packing to; it will be the label we jump to from + ; zbranch. + dq dup, unroll3 + dq rsi, rsi, add_reg64_indirect_reg64 + dq pack_next, lit, 8, packalign, early_here_store ; This was "zbranch". dq litstring, "0branch", early_create, early_self_codeword, early_here dq fetch - ; TODO - dq lit, 8, packalign, early_here_store + dq rax, pop_reg64 + dq rax, rax, test_reg64_reg64 + ; Retrieve the saved address for the start of "branch". Compute the + ; relative offset from the current address to it. Add two bytes to allow + ; for the length of the jmp instruction. + dq dup, lit, 4, roll, sub, lit, 2, add + ; It's slightly counterintuitive that the condition is called cc_equal; + ; that's a result of the condition names favoring cmp over test. While cmp + ; simulates subtraction, test simulates biwise AND. What we're testing is + ; that the result is zero. + dq cc_equal, jmp_cc_rel_imm8 + dq lods64 + dq pack_next, lit, 8, packalign, early_here_store ; This name is exactly eight bytes long. Don't even ask (go read litstring's ; code if you really need to know). @@ -4249,7 +4263,7 @@ defword set_reg8_cc, 0 ; condition code name defword jmp_cc_rel_imm8, 0 dq docol - dq unroll3, swap, conditioncode, lit, 0x70, opcodecc + dq roll3, swap, conditioncode, lit, 0x70, opcodecc dq swap, pack8 dq exit -- cgit 1.4.1