summaryrefslogtreecommitdiff
path: root/Optimizing-assembly-code.md
diff options
context:
space:
mode:
authorRangi <remy.oukaour+rangi42@gmail.com>2020-04-17 15:06:16 -0400
committerRangi <remy.oukaour+rangi42@gmail.com>2020-04-17 15:06:16 -0400
commit49298af70dd6457e4d4bf270a7fcb00dbf625139 (patch)
treeff008c90b47d3bf916d6d340e9ed081afbd2c46d /Optimizing-assembly-code.md
parentc0e842ee0e91dd8a11bdfa96e9c921e01be07d15 (diff)
Divide a by 8
Diffstat (limited to 'Optimizing-assembly-code.md')
-rw-r--r--Optimizing-assembly-code.md14
1 files changed, 12 insertions, 2 deletions
diff --git a/Optimizing-assembly-code.md b/Optimizing-assembly-code.md
index 2c308b7..54af5ba 100644
--- a/Optimizing-assembly-code.md
+++ b/Optimizing-assembly-code.md
@@ -22,7 +22,7 @@ WikiTI's advice fully applies here:
- [Rotate the bits of `a`](#rotate-the-bits-of-a)
- [Set `a` to some constant minus `a`](#set-a-to-some-constant-minus-a)
- [Set `a` to one constant or another depending on the carry flag](#set-a-to-one-constant-or-another-depending-on-the-carry-flag)
- - [Shift `a` right by 3 bits](#shift-a-right-by-3-bits)
+ - [Divide `a` by 8 (shift `a` right 3 bits)](#divide-a-by-8-shift-a-right-3-bits)
- [Set `a` to some value plus carry](#set-a-to-some-value-plus-carry)
- [Load from HRAM to `a` or from `a` to HRAM](#load-from-hram-to-a-or-from-a-to-hram)
- [16-bit registers](#16-bit-registers)
@@ -298,11 +298,21 @@ If `CVAL` is 0 and `NCVAL` is 1 (i.e. set `a` to 0 if carry, or 1 if not carry),
```
-### Shift `a` right by 3 bits
+### Divide `a` by 8 (shift `a` right 3 bits)
Don't do:
```asm
+ ; 6 bytes, 9 cycles
+ ; (15 bytes, at least 21 cycles, counting the definition of SimpleDivide)
+ ld c, 8 ; divisor
+ call SimpleDivide
+ ld a, b ; quotient
+```
+
+And don't do:
+
+```asm
; 6 bytes, 6 cycles
srl a
srl a