diff options
| author | Rangi <remy.oukaour+rangi42@gmail.com> | 2021-02-12 20:39:04 -0500 |
|---|---|---|
| committer | Rangi <remy.oukaour+rangi42@gmail.com> | 2021-02-12 20:39:04 -0500 |
| commit | 5804a3c22e2215c5d4499fd3ab2496d30248ea46 (patch) | |
| tree | 04a36b40f54ef32edff62ce0ed98e766facec763 /Optimizing-assembly-code.md | |
| parent | 81a178ec1bb48a4f1223837d6539bc0916e19927 (diff) | |
...
Diffstat (limited to 'Optimizing-assembly-code.md')
| -rw-r--r-- | Optimizing-assembly-code.md | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/Optimizing-assembly-code.md b/Optimizing-assembly-code.md index 9d1a19e..9dd0ec2 100644 --- a/Optimizing-assembly-code.md +++ b/Optimizing-assembly-code.md @@ -1377,22 +1377,27 @@ Don't do: ```asm ; 4 additional bytes, 10 additional cycles - call GetOffset - ... - -GetOffset: (some code) + call Function + (some more code) + +Function: + (function code) ret ``` -if `GetOffset` is only called a handful of times. Instead, do: +if `Function` is only called a handful of times. Instead, do: ```asm -; GetOffset (some code) + + ; Function + (function code) + + (some more code) ``` -You can set `(some code)` apart with blank lines and put a comment on top to make its self-contained nature clear without the extra `call` and `ret`. +You shouldn't do this if `Function` used any `ret`urns besides the one at the very end, or if inlining its code would make some `jr`s too distant from their targets. ### Fallthrough @@ -1400,33 +1405,33 @@ You can set `(some code)` apart with blank lines and put a comment on top to mak Don't do: ```asm - ... + (some code) call Function ret Function: - (some code) + (function code) ret ``` And don't do: ```asm - ... + (some code) jp Function Function: - (some code) + (function code) ret ``` But do: ```asm - ... + (some code) ; fallthrough Function: - (some code) + (function code) ret ``` @@ -1491,6 +1496,14 @@ And don't do: ... ``` +And don't do: + +```asm + ; 3 bytes, 3 or 6 cycles + call z, $0038 + ... +``` + But do: ```asm |
