From 65ea11eb0dfd29f572e83a2f3fe77d992e115b1c Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 13 Apr 2026 23:35:44 +0200 Subject: Add a note on indirect jumps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 01c4847..33ebf85 100644 --- a/README.md +++ b/README.md @@ -437,7 +437,7 @@ already telling the caller that the `x` register is involved on this scenario. ## Use `.proc` for functions The `.proc` control statement guarantees a new lexical scope, so named labels -will not clash with named labels from other scopes. There are really no +will not clash with named labels from other scopes. There are (almost) no downsides to it. ``` assembly @@ -449,8 +449,17 @@ bad: .endproc ``` -Hence, labels should only be used for control flow and referencing data on ROM -space. +I say "(almost)" as I have seen at least one situation in which discarding any +kind of scoping could be useful if performance was paramount. That is, imagine a +16-bit pointer to a function that can be set to different handlers for enemy +movement. This could be done in multiple ways, but the most performant way would +be to just `jmp (pointer)`, and then let each handler perform a `jmp +@known_return_address` instead of a mere `rts`. Hence, if you are on corner +cases like these, I think it's fair to go the optimal route. In other cases, +prefer readability. + +Otherwise, labels should only be used for control flow and referencing data on +ROM space. ## Avoid too many anonymous labels -- cgit v1.2.3