summaryrefslogtreecommitdiff
path: root/Optimizing-assembly-code.md
diff options
context:
space:
mode:
authorRangi <remy.oukaour+rangi42@gmail.com>2021-03-12 14:05:16 -0500
committerRangi <remy.oukaour+rangi42@gmail.com>2021-03-12 14:05:16 -0500
commitf9f1695821cdd632761c9a487bb710d61a3fbc7f (patch)
tree73441df132acfba437e655c96e13768ae8218359 /Optimizing-assembly-code.md
parentabbcc567a1f93a078ab297d5238afe27a87cbd63 (diff)
Conditional return
Diffstat (limited to 'Optimizing-assembly-code.md')
-rw-r--r--Optimizing-assembly-code.md32
1 files changed, 28 insertions, 4 deletions
diff --git a/Optimizing-assembly-code.md b/Optimizing-assembly-code.md
index d18495f..51c512d 100644
--- a/Optimizing-assembly-code.md
+++ b/Optimizing-assembly-code.md
@@ -56,8 +56,9 @@ WikiTI's advice fully applies here:
- [Inlining](#inlining)
- [Fallthrough](#fallthrough)
- [Conditional fallthrough](#conditional-fallthrough)
- - [Call a function depending on a flag](#call-a-function-depending-on-a-flag)
- - [Call `rst $38` depending on a flag](#call-rst-38-depending-on-a-flag)
+ - [Conditional return](#conditional-return)
+ - [Conditional call](#conditional-call)
+ - [Conditional `rst $38`](#conditional-rst-38)
- [Jump and lookup tables](#jump-and-lookup-tables)
- [Chain comparisons](#chain-comparisons)
@@ -1471,7 +1472,30 @@ But do:
```
-### Call a function depending on a flag
+## Conditional return
+
+(The example uses `z`, but `nz`, `c`, or `nc` would also work.)
+
+Don't do:
+
+```asm
+ ; 3 bytes, 3 or 6 cycles
+ jr z, .skip
+ ret
+.skip
+ ...
+```
+
+But do:
+
+```asm
+ ; 1 byte, 5 or 2 cycles
+ ret nz
+ ...
+```
+
+
+### Conditional call
(The example uses `z`, but `nz`, `c`, or `nc` would also work.)
@@ -1508,7 +1532,7 @@ But do:
```
-### Call `rst $38` depending on a flag
+### Conditional `rst $38`
(The example uses `z`, but `nz`, `c`, or `nc` would also work.)