From 4f1a9c660108e5fb94d5b19ee649427b8aafd96b Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 2 Feb 2026 22:38:16 +0100 Subject: Add the .fallthrough control statement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is exclusive to 'nasm' and it allows the developer to explicitly tell the assembler than a "fall through" condition is actually desired: it's not a mistake. This comes in two flavors. The first, without arguments, just makes this explicit without much enforcement. The second allows you to pass an argument which is the name of the function or label you are expecting to fall through. The assembler will error out if the fall through address is not the expected one, hence telling the programmer whenever the fall through condition they thought in the past is no longer true (e.g. the function has moved somewhere else in the code). Signed-off-by: Miquel Sabaté Solà --- tests/bad_fallthrough.s | 27 +++++++++++++++++++++++++++ tests/expected/bad_fallthrough.txt | 4 ++++ tests/expected/fallthrough.nes | Bin 0 -> 21 bytes tests/expected/fallthrough.txt | 0 tests/fallthrough.s | 23 +++++++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 tests/bad_fallthrough.s create mode 100644 tests/expected/bad_fallthrough.txt create mode 100644 tests/expected/fallthrough.nes create mode 100644 tests/expected/fallthrough.txt create mode 100644 tests/fallthrough.s (limited to 'tests') diff --git a/tests/bad_fallthrough.s b/tests/bad_fallthrough.s new file mode 100644 index 0000000..ac17ade --- /dev/null +++ b/tests/bad_fallthrough.s @@ -0,0 +1,27 @@ +.segment "HEADER" + .byte 'N', 'E', 'S', $1A + .byte $02, $01 + .byte $00 + .byte $00 + +.segment "CODE" + +.proc foo + lda #0 + .fallthrough bar +.endproc + +.fallthrough bar +.fallthrough other + lda #0 + +.proc bar + lda #0 + .fallthrough other +.endproc + +.proc other + rts +.endproc + +.fallthrough other diff --git a/tests/expected/bad_fallthrough.txt b/tests/expected/bad_fallthrough.txt new file mode 100644 index 0000000..f105880 --- /dev/null +++ b/tests/expected/bad_fallthrough.txt @@ -0,0 +1,4 @@ +error: statement does not fall through (bad_fallthrough.s: line 11) +error: statement does not fall through (bad_fallthrough.s: line 14) +error: statement does not fall through (bad_fallthrough.s: line 15) +error: statement does not fall through (bad_fallthrough.s: line 27) diff --git a/tests/expected/fallthrough.nes b/tests/expected/fallthrough.nes new file mode 100644 index 0000000..976f8fc Binary files /dev/null and b/tests/expected/fallthrough.nes differ diff --git a/tests/expected/fallthrough.txt b/tests/expected/fallthrough.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/fallthrough.s b/tests/fallthrough.s new file mode 100644 index 0000000..2340ee8 --- /dev/null +++ b/tests/fallthrough.s @@ -0,0 +1,23 @@ +.segment "HEADER" + .byte 'N', 'E', 'S', $1A + .byte $02, $01 + .byte $00 + .byte $00 + +.segment "CODE" + +.proc foo + lda #0 + .fallthrough bar +.endproc + +.fallthrough bar + +.proc bar + lda #0 + .fallthrough other +.endproc + +.proc other + rts +.endproc -- cgit v1.2.3