From c751ceaf07ae9be514e7b6414730fe0919a75e54 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 11 Mar 2025 21:55:30 +0100 Subject: Add a note on pseudo-instructions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 8b6d5b8..5aff6a7 100644 --- a/README.md +++ b/README.md @@ -245,6 +245,28 @@ LDA #01 ; bad! lda #01 ; good! ``` +One good idea for `.macro` is to use them to define pseudo-instructions, as it's +done in other assembly languages like RISC-V. For example, on [these scrolling +examples](https://github.com/mssola/code.nes/tree/main/scroll) there is a macro +for the pseudo-instruction `JAL`, which makes explicit when a `jmp` has been +used instead of `jsr` for reducing the stack usage on tail calls. In this +scenario, you can find code like this: + +```assembly +.proc foo + ;; Previous code that might jump/branch to @end. + + lda Some::Variable + bne @end + JAL prepare_next_column +@end: + rts +.endproc +``` + +Here the casing makes explicit that `JAL` is actually a pseudo-instruction, and +so that it follows somewhat different rules than the ones by its side. + ## Use the `@` prefix for named labels which affect the control flow Named labels which are part of the control flow are to use the `@` symbol as a -- cgit v1.2.3