summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Optimizing-assembly-code.md42
1 files changed, 42 insertions, 0 deletions
diff --git a/Optimizing-assembly-code.md b/Optimizing-assembly-code.md
index f6e4651..8a90e9e 100644
--- a/Optimizing-assembly-code.md
+++ b/Optimizing-assembly-code.md
@@ -21,6 +21,7 @@ WikiTI's advice fully applies here:
- [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)
+ - [Set `a` to some value plus carry](#set-a-to-some-value-plus-carry)
- [Multiply `hl` by 2](#multiply-hl-by-2)
- [Add `a` to a 16-bit register](#add-a-to-a-16-bit-register)
- [Add `a` to an address](#add-a-to-an-address)
@@ -233,6 +234,47 @@ But do:
```
+### Set `a` to some value plus carry
+
+(The example uses `b` and `c`, but any registers besides `a` would also work, including `[hl]`.)
+
+Don't do:
+
+```asm
+ ; 4 bytes, 4 cycles
+ ld b, a
+ ld a, c
+ adc 0
+```
+
+But do:
+
+```asm
+ ; 3 bytes, 3 cycles
+ ld b, a
+ adc c
+ sub b
+```
+
+And don't do:
+
+```asm
+ ; 5 bytes, 5 cycles
+ ld b, a
+ ld a, N
+ adc 0
+```
+
+But do:
+
+```asm
+ ; 4 bytes, 4 cycles
+ ld b, a
+ adc N
+ sub b
+```
+
+
### Multiply `hl` by 2
Don't do: