diff options
Diffstat (limited to 'Optimizing-assembly-code.md')
-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 |