From ddc577962cc2f65b7cfe74edc4b15cbe865220d8 Mon Sep 17 00:00:00 2001 From: Rangi Date: Wed, 25 Nov 2020 16:01:17 -0500 Subject: Optimize hl|bc|de = Foo + a --- Optimizing-assembly-code.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'Optimizing-assembly-code.md') 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 -- cgit v1.2.3