summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRangi <remy.oukaour+rangi42@gmail.com>2021-05-21 00:09:25 -0400
committerRangi <remy.oukaour+rangi42@gmail.com>2021-05-21 00:09:25 -0400
commitd95d85bb13cd4f9b0887e08a094294f68b6ae330 (patch)
tree7c6573e2e806840fa88c46c0e48fae76ad70a50d
parent5f16802ad18d435d21294ab2134217970b51b90e (diff)
ei + ret -> reti
-rw-r--r--Optimizing-assembly-code.md19
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