diff --git a/compiler/src/prog8/compiler/target/c64/codegen/BuiltinFunctionsAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/BuiltinFunctionsAsmGen.kt index ce76e38c0..c73edfaf0 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/BuiltinFunctionsAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/BuiltinFunctionsAsmGen.kt @@ -965,7 +965,15 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val asmgen.out(" sta P8ESTACK_LO,x | tya | sta P8ESTACK_HI,x | dex") } else { val reg = resultRegister ?: RegisterOrPair.AY - val needAsave = !(fcall.args[0] is DirectMemoryRead || fcall.args[0] is NumericLiteralValue || fcall.args[0] is IdentifierReference) + var needAsave = !(fcall.args[0] is DirectMemoryRead || fcall.args[0] is NumericLiteralValue || fcall.args[0] is IdentifierReference) + if(!needAsave) { + val mr0 = fcall.args[0] as? DirectMemoryRead + val mr1 = fcall.args[1] as? DirectMemoryRead + if (mr0 != null) + needAsave = mr0.addressExpression !is NumericLiteralValue && mr0.addressExpression !is IdentifierReference + if (mr1 != null) + needAsave = needAsave or (mr1.addressExpression !is NumericLiteralValue && mr1.addressExpression !is IdentifierReference) + } when(reg) { RegisterOrPair.AX -> { asmgen.assignExpressionToRegister(fcall.args[1], RegisterOrPair.A) // lsb diff --git a/examples/test.p8 b/examples/test.p8 index 39c0ba4aa..93d7cc7ec 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -4,29 +4,24 @@ main { sub start() { - ubyte ib - uword iw - ubyte xx - xx=0 + uword ptr = $4000 - for ib in 241 to 253 step 2 { - txt.print_ub(ib) - txt.nl() - xx++ - } + @(ptr) = $34 + @(ptr+1) = $ea - for ib in 10 downto 2 step -2 { - txt.print_ub(ib) - txt.nl() - xx-- - } - for ib in 6 downto 0 step -2 { - txt.print_ub(ib) - txt.nl() - xx-- - } + txt.print_ubhex(@(ptr), 1) + txt.print_ubhex(@(ptr+1), 1) + txt.nl() - txt.print_ub(xx) + uword ww = mkword(@(ptr+1), @(ptr)) ; TODO FIX + txt.print_uwhex(ww,1) + txt.nl() + + ubyte low = @(ptr) + ubyte high = @(ptr+1) + ww = mkword(high, low) + txt.print_uwhex(ww,1) + txt.nl() } }