diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmOptimizer.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmOptimizer.kt index c820e49ab..7aea2813c 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmOptimizer.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmOptimizer.kt @@ -583,8 +583,8 @@ private fun optimizeJsrRtsAndOtherCombinations(linesByFour: Sequence bne Addr diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt index 869249fc5..00d1ed15f 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/FunctionCallAsmGen.kt @@ -82,7 +82,7 @@ internal class FunctionCallAsmGen(private val program: PtProgram, private val as is PtAddressOf -> false is PtIdentifier -> false is PtIrRegister -> false - is PtMemoryByte -> return usesOtherRegistersWhileEvaluating(arg.address) + is PtMemoryByte -> true // TODO might not actually need extra registers if the value has to end up in A is PtNumber -> false is PtBool -> false else -> true @@ -110,9 +110,9 @@ internal class FunctionCallAsmGen(private val program: PtProgram, private val as throw AssemblyError("call argument evaluation problem: can't save cpu statusregister parameter ${call.position}") } else { - if(usedX()) asmgen.saveRegisterStack(CpuRegister.X, false) - if(usedY()) asmgen.saveRegisterStack(CpuRegister.Y, false) - if(usedA()) asmgen.saveRegisterStack(CpuRegister.A, false) + if(usedX()) asmgen.saveRegisterStack(CpuRegister.X, usedA()) + if(usedY()) asmgen.saveRegisterStack(CpuRegister.Y, usedA()) + if(usedA()) asmgen.saveRegisterStack(CpuRegister.A, usedA()) val used = argumentViaRegister(sub, IndexedValue(it, param.second), arg) if(usedA()) asmgen.restoreRegisterStack(CpuRegister.A, false) if(usedY()) asmgen.restoreRegisterStack(CpuRegister.Y, true) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index b9cdb647a..fbb36e2b8 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,9 +1,7 @@ TODO ==== -https://github.com/irmen/prog8/issues/136 (string.find register order issue) - -other issues on github. +See open issues on github. optimize signed byte/word division by powers of 2 (and shift right?), it's now using divmod routine. (also % ?) see inplacemodificationByteVariableWithLiteralval() and inplacemodificationSomeWordWithLiteralval() @@ -30,6 +28,12 @@ optimize signed byte/word division by powers of 2 (and shift right?), it's now u lda $4 +Improve register load order in subroutine call args assignments: +in certain situations, the "wrong" order of evaluation of function call arguments is done which results +in overwriting registers that already got their value, which requires a lot of stack juggling (especially on plain 6502 cpu!) +Maybe this routine can be made more intelligent. See usesOtherRegistersWhileEvaluating() and argumentsViaRegisters(). + + Future Things and Ideas ^^^^^^^^^^^^^^^^^^^^^^^ Compiler: