From 932fe3dc341690688b706b70d56336d899d2246f Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 15 Dec 2025 13:15:19 +0100 Subject: Report on multi-byte values on arithmetic evaluation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When evaluating an arithmetic operation, check on whether it theoretically spans more than one byte, and set it on the resulting Bundle.size. It's up to the caller to decide on whether that makes sense or not. This fixes situations in which: sta $200 + 1 was marked as having 2 bytes for the size as only the "1" was being considered for the size on this operation. This would then signal the "sta" evaluation that it was zeropage instead of absolute addressing. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/assembler.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lib/xixanta/src') diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index 6a83dcb..e7843a3 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -1354,6 +1354,13 @@ impl<'a> Assembler<'a> { right.bytes[0] = byte_result[0]; right.bytes[1] = byte_result[1]; + // If the operation makes the end result bigger than what 1 byte can fit + // (or it already was bigger before this operation), then we have to + // assume that this is a 16-bit value. + if res > 0x00FF { + right.size = 3; + } + Ok(right) } @@ -3576,6 +3583,31 @@ cpx #(4 * var2)"#, assert_instruction("bit $1001", &[0x2C, 0x01, 0x10]); } + #[test] + fn arithmetic_memory_access() { + let res = just_bundles( + r#" +m_var = $200 +sta $200 + 1 +sta m_var + 1 + "#, + ); + + assert_eq!(res.len(), 2); + + // sta in both cases. + + assert_eq!(res[0].size, 3); + assert_eq!(res[0].bytes[0], 0x8D); + assert_eq!(res[0].bytes[1], 0x01); + assert_eq!(res[0].bytes[2], 0x02); + + assert_eq!(res[1].size, 3); + assert_eq!(res[1].bytes[0], 0x8D); + assert_eq!(res[1].bytes[1], 0x01); + assert_eq!(res[1].bytes[2], 0x02); + } + // Labels & branching #[test] -- cgit v1.2.3