From 8d177beb78fb32d001249678f69746da7f2ee0c3 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 24 Sep 2023 14:03:31 +0200 Subject: [PATCH] fix possible register corruption when calling asmsubs that require Carry flag as a parameter --- .../src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt index 25eaba7cd..e1d88b83f 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt @@ -141,13 +141,14 @@ internal class FunctionCallAsmGen(private val program: PtProgram, private val as } is PtIdentifier -> { val sourceName = asmgen.asmVariableName(value) + // note: cannot use X register here to store A because it might be used for other arguments asmgen.out(""" - tax + pha clc lda $sourceName beq + sec -+ txa""") ++ pla""") } else -> { asmgen.assignExpressionToRegister(value, RegisterOrPair.A)