diff options
| author | Irene Knapp <ireneista@irenes.space> | 2025-11-08 18:50:31 -0800 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2025-11-08 18:50:31 -0800 |
| commit | 9dbf42f2138b93987b42069dd3aee4d6fd7917fd (patch) | |
| tree | fe9c513ea4043a6c7c33b69f70734558f10441c4 /quine.asm | |
| parent | 3e8b0109dc5303d0ea12672a12de96bc8b9d0c5d (diff) | |
implement branch and 0branch; fix jmp_cc_rel_imm8
Force-Push: yes Change-Id: I45c0a5e729cae2493e341ad3b6145708826383ab
Diffstat (limited to 'quine.asm')
| -rw-r--r-- | quine.asm | 24 |
1 files changed, 19 insertions, 5 deletions
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 |