diff options
author | Rangi <remy.oukaour+rangi42@gmail.com> | 2020-08-22 16:06:37 -0400 |
---|---|---|
committer | Rangi <remy.oukaour+rangi42@gmail.com> | 2020-08-22 16:06:37 -0400 |
commit | 611e0db45ed59005e3429a76b4e4f870434badda (patch) | |
tree | e1265f042a5b96f23fc6f7ea256b23efeeaafa15 /Optimizing-assembly-code.md | |
parent | f14d7492c3a2380fb4719ca89bc236cbebb5857b (diff) |
`jr nc, .ok / inc|dec a / .ok` == `ccf / adc|sbc 0`
Diffstat (limited to 'Optimizing-assembly-code.md')
-rw-r--r-- | Optimizing-assembly-code.md | 38 |
1 files changed, 4 insertions, 34 deletions
diff --git a/Optimizing-assembly-code.md b/Optimizing-assembly-code.md index a6d0d65..93fa03a 100644 --- a/Optimizing-assembly-code.md +++ b/Optimizing-assembly-code.md @@ -24,7 +24,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) - - [Increment or decrement `a` depending on the carry flag](#increment-or-decrement-a-depending-on-the-carry-flag) + - [Increment or decrement `a` when the carry flag is set](#increment-or-decrement-a-when-the-carry-flag-is-set) - [Divide `a` by 8 (shift `a` right 3 bits)](#divide-a-by-8-shift-a-right-3-bits) - [Divide `a` by 16 (shift `a` right 4 bits)](#divide-a-by-16-shift-a-right-4-bits) - [Set `a` to some value plus carry](#set-a-to-some-value-plus-carry) @@ -314,19 +314,19 @@ If `CVAL` is 0 and `NCVAL` is 1 (i.e. set `a` to 0 if carry, or 1 if not carry), ``` -### Increment or decrement `a` depending on the carry flag +### Increment or decrement `a` when the carry flag is set Don't do: ```asm - ; 3 bytes, 3 or 4 cycles + ; 3 bytes, 3 cycles jr nc, .ok inc a .ok ``` ```asm - ; 3 bytes, 3 or 4 cycles + ; 3 bytes, 3 cycles jr nc, .ok dec a .ok @@ -342,36 +342,6 @@ But do: sbc 0 ; 2 bytes, 2 cycles ``` -And don't do: - -```asm - ; 3 bytes, 3 or 4 cycles - jr c, .ok - inc a -.ok -``` - -```asm - ; 3 bytes, 3 or 4 cycles - jr c, .ok - dec a -.ok -``` - -But do: - -```asm - ; 3 bytes, 3 cycles - ccf - adc 0 -``` - -```asm - ; 3 bytes, 3 cycles - ccf - sbc 0 -``` - ### Divide `a` by 8 (shift `a` right 3 bits) |