fix invalid handling of X register functioncall result value

This commit is contained in:
Irmen de Jong 2021-01-05 02:44:55 +01:00
parent 6fa7debee5
commit 45c9cc97d9
2 changed files with 11 additions and 3 deletions

View File

@ -144,12 +144,11 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
is Subroutine -> {
asmgen.saveXbeforeCall(value)
asmgen.translateFunctionCall(value)
if(!sub.regXasResult())
asmgen.restoreXafterCall(value)
val returnValue = sub.returntypes.zip(sub.asmReturnvaluesRegisters).singleOrNull { it.second.registerOrPair!=null } ?:
sub.returntypes.zip(sub.asmReturnvaluesRegisters).single { it.second.statusflag!=null }
when (returnValue.first) {
DataType.STR -> {
asmgen.restoreXafterCall(value)
when(assign.target.datatype) {
DataType.UWORD -> {
// assign the address of the string result value
@ -171,9 +170,11 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
}
DataType.FLOAT -> {
// float result from function sits in FAC1
asmgen.restoreXafterCall(value)
assignFAC1float(assign.target)
}
else -> {
// do NOT restore X register before assigning the result values first
when (returnValue.second.registerOrPair) {
RegisterOrPair.A -> assignRegisterByte(assign.target, CpuRegister.A)
RegisterOrPair.X -> assignRegisterByte(assign.target, CpuRegister.X)
@ -189,7 +190,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
throw AssemblyError("should be just one register byte result value")
}
}
// we've processed the result value in the X register by now, so it's now safe to restore it:
// we've processed the result value in the X register by now, so it's now finally safe to restore it
asmgen.restoreXafterCall(value)
}
}

View File

@ -5,7 +5,14 @@
main {
asmsub opcode(uword instr_info_ptr @AY, ubyte addr_mode @X) clobbers(X) -> ubyte @A, ubyte @Pc {
%asm {{
rts
}}
}
sub start () {
ubyte xx = opcode(0, 1)
test_stack.test()