summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Optimizing-assembly-code.md17
1 files changed, 17 insertions, 0 deletions
diff --git a/Optimizing-assembly-code.md b/Optimizing-assembly-code.md
index 2c4b827..867cb07 100644
--- a/Optimizing-assembly-code.md
+++ b/Optimizing-assembly-code.md
@@ -201,6 +201,23 @@ If `FOO` equals `BAR - 2`, then do:
sbc -BAR ; -1 becomes BAR - 2 aka FOO, 0 becomes BAR
```
+If `FOO` is 1 and `BAR` is 0 (i.e. set `a` to 1 if carry or 0 if not carry), then do:
+
+```asm
+ ; 3 bytes, 3 cycles
+ ccf ; invert carry flag
+ sbc a ; if originally carry, then 0, else $ff aka -1
+ inc a ; 0 becomes 1, -1 becomes 0
+```
+
+If `FOO` is 0 and `BAR` is 0 (i.e. set `a` to 0 if carry or 1 if not carry), then do:
+
+```asm
+ ; 2 bytes, 2 cycles
+ sbc a ; if carry, then $ff aka -1, else 0
+ inc a ; -1 becomes 0, 0 becomes 1
+```
+
### Shift `a` right by 3 bits