diff options
author | Rangi <remy.oukaour+rangi42@gmail.com> | 2020-03-12 19:30:37 -0400 |
---|---|---|
committer | Rangi <remy.oukaour+rangi42@gmail.com> | 2020-03-12 19:30:37 -0400 |
commit | cd7db09433ebbb36c31ff6a5d10d37159c1ec715 (patch) | |
tree | 5e2b1ad075bbe081ccd08e08cdef3999d060a29f | |
parent | 89c6678c9b07de0d5d7316b2aa11dee0c00d4edc (diff) |
Conditional rst $38
-rw-r--r-- | Optimizing-assembly-code.md | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Optimizing-assembly-code.md b/Optimizing-assembly-code.md index d9b3811..428add0 100644 --- a/Optimizing-assembly-code.md +++ b/Optimizing-assembly-code.md @@ -40,6 +40,7 @@ WikiTI's advice fully applies here: - [Call `hl`](#call-hl) - [Inlining](#inlining) - [Fallthrough](#fallthrough) + - [Call `rst $38` depending on a flag](#call-rst-38-depending-on-a-flag) - [Jump and lookup tables](#jump-and-lookup-tables) - [Chain comparisons](#chain-comparisons) @@ -678,6 +679,41 @@ Function: You can still `call Function` elsewhere, but one tail call can be optimized into a fallthrough. +### Call `rst $38` depending on a flag + +(The example uses `z`, but `nz`, `c`, or `nc` would also work.) + +Don't do: + +```asm + ; 5 bytes, 3 or 14 cycles + call z, RstVector38 + ... + +RstVector38: + rst $38 + ret +``` + +And don't do: + +```asm + ; 3 bytes, 2 or 7 cycles + jr nz, .no_rst_38 + rst $38 +.no_rst_38 + ... +``` + +But do: + +```asm + ; 2 bytes, 2 or 7 cycles + jr z, @ - 1 ; the byte for @ - 1 is $ff, which is the opcode for rst $38 + ... +``` + + ## Jump and lookup tables |