diff options
| -rw-r--r-- | Optimizing-assembly-code.md | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Optimizing-assembly-code.md b/Optimizing-assembly-code.md index 0c5e733..9d27bde 100644 --- a/Optimizing-assembly-code.md +++ b/Optimizing-assembly-code.md @@ -62,6 +62,7 @@ WikiTI's advice fully applies here: - [Conditional return](#conditional-return) - [Conditional call](#conditional-call) - [Conditional `rst $38`](#conditional-rst-38) + - [Enable interrupts and return](#enable-interrupts-and-return) - [Jump and lookup tables](#jump-and-lookup-tables) - [Chain comparisons](#chain-comparisons) @@ -1841,6 +1842,24 @@ But do: (The label `@` evaluates to the current `pc` value, which in `jr z, @ + 1` is right before the `jr` instruction. The instruction consists of two bytes, the opcode and the relative offset. `@ + 1` evaluates to in-between those two bytes. The `jr` instruction encodes its offset relative to the *end* of the instruction, i.e. the *next* `pc` value after the instruction has been read, so the relative offset is `-1`, aka `$ff`.) +### Enable interrupts and return + +Don't do: + +```asm + ; 2 bytes, 5 cycles + ei + ret +``` + +But do: + +```asm + ; 1 byte, 4 cycles + reti +``` + + ## Jump and lookup tables |
