From 5804a3c22e2215c5d4499fd3ab2496d30248ea46 Mon Sep 17 00:00:00 2001 From: Rangi Date: Fri, 12 Feb 2021 20:39:04 -0500 Subject: ... --- Optimizing-assembly-code.md | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'Optimizing-assembly-code.md') 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 -- cgit v1.2.3