summaryrefslogtreecommitdiff
path: root/Optimizing-assembly-code.md
diff options
context:
space:
mode:
authorRangi <remy.oukaour+rangi42@gmail.com>2020-11-25 16:01:17 -0500
committerRangi <remy.oukaour+rangi42@gmail.com>2020-11-25 16:01:17 -0500
commitddc577962cc2f65b7cfe74edc4b15cbe865220d8 (patch)
tree11b4cd35cdd31ed246e03e4b0fd0efba7ca197fc /Optimizing-assembly-code.md
parent844036cf125c7d44aa1cc80a5056b763b6eb54d5 (diff)
Optimize hl|bc|de = Foo + a
Diffstat (limited to 'Optimizing-assembly-code.md')
-rw-r--r--Optimizing-assembly-code.md26
1 files changed, 26 insertions, 0 deletions
diff --git a/Optimizing-assembly-code.md b/Optimizing-assembly-code.md
index b3453b4..d2fafc2 100644
--- a/Optimizing-assembly-code.md
+++ b/Optimizing-assembly-code.md
@@ -177,6 +177,8 @@ The exception is if you need to set the zero flag when the operation results in
(This optimization is from [Retro Programming](http://www.retroprogramming.com/2014/01/fast-z80-bit-reversal.html)).
+(The example uses `b` and `c`, but any of `d`, `e`, `h`, or `l` would also work.)
+
Don't do:
```asm
@@ -769,6 +771,30 @@ Don't do:
add hl, de
```
+And don't do:
+
+```asm
+ ; 8 bytes, 8 cycles
+ ld hl, Address
+ add l
+ ld l, a
+ adc h
+ sub l
+ ld h, a
+```
+
+And don't do:
+
+```asm
+ ; 8 bytes, 7 or 8 cycles
+ ld h, HIGH(Address)
+ add LOW(Address)
+ ld l, a
+ jr nc, .no_carry
+ inc h
+.no_carry
+```
+
But do:
```asm