diff options
-rw-r--r-- | Optimizing-assembly-code.md | 14 |
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 |