fix wrong code for inplace modification of a pointervariable's memory value

This commit is contained in:
Irmen de Jong 2021-12-10 13:39:54 +01:00
parent 3d743a1ba1
commit e342311bef
3 changed files with 24 additions and 9 deletions

View File

@ -364,6 +364,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
private fun inplaceModification_byte_value_to_pointer(pointervar: IdentifierReference, operator: String, value: Expression) {
asmgen.assignExpressionToVariable(value, "P8ZP_SCRATCH_B1", DataType.UBYTE, null)
val sourceName = asmgen.loadByteFromPointerIntoA(pointervar)
when (operator) {
// note: ** (power) operator requires floats.
"+" -> asmgen.out(" clc | adc P8ZP_SCRATCH_B1")
@ -394,8 +395,6 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
"^", "xor" -> asmgen.out(" eor P8ZP_SCRATCH_B1")
else -> throw AssemblyError("invalid operator for in-place modification $operator")
}
// TODO THIS IS WRONG:????
val sourceName = asmgen.loadByteFromPointerIntoA(pointervar)
asmgen.storeAIntoZpPointerVar(sourceName)
}

View File

@ -3,7 +3,7 @@ TODO
For next compiler release (7.5)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
check correctness of inplaceModification_byte_value_to_pointer()
- allow cx16.rX as loop variable in forloops (now requires unqualified identifiername)
...

View File

@ -3,11 +3,27 @@
main {
sub start() {
word llw = 300
cx16.r0s = 9 * 2 * 10 * llw
cx16.r1s = llw * 9 * 2 * 10
cx16.r3s = llw / 30 / 3
cx16.r4s = llw / 2 * 10
cx16.r5s = llw * 90 / 5 ; not optimized because of loss of integer division precision
ubyte @zp xx
for xx in 0 to 10 {
txt.print_ub(xx)
txt.spc()
}
txt.nl()
for cx16.r0L in 0 to 10 {
txt.print_ub(cx16.r0L)
txt.spc()
}
txt.nl()
for main.derp.xx in 0 to 10 {
txt.print_ub(main.derp.xx)
txt.spc()
}
txt.nl()
}
sub derp() {
ubyte xx
}
}