diff --git a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AugmentableAssignmentAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AugmentableAssignmentAsmGen.kt index b2a7d6f67..05f9b4ca1 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AugmentableAssignmentAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AugmentableAssignmentAsmGen.kt @@ -171,14 +171,14 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, is IdentifierReference -> { val pointer = memory.addressExpression as IdentifierReference when { - valueLv != null -> inplaceModification_byte_litval_to_memory(pointer, operator, valueLv.toInt()) - ident != null -> inplaceModification_byte_variable_to_memory(pointer, operator, ident) + valueLv != null -> inplaceModification_byte_litval_to_pointer(pointer, operator, valueLv.toInt()) + ident != null -> inplaceModification_byte_variable_to_pointer(pointer, operator, ident) // TODO more specialized code for types such as memory read etc. value is TypecastExpression -> { if (tryRemoveRedundantCast(value, target, operator)) return - inplaceModification_byte_value_to_memory(pointer, operator, value) + inplaceModification_byte_value_to_pointer(pointer, operator, value) } - else -> inplaceModification_byte_value_to_memory(pointer, operator, value) + else -> inplaceModification_byte_value_to_pointer(pointer, operator, value) } } else -> { @@ -239,15 +239,15 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, return false } - private fun inplaceModification_byte_value_to_memory(pointervar: IdentifierReference, operator: String, value: Expression) { + private fun inplaceModification_byte_value_to_pointer(pointervar: IdentifierReference, operator: String, value: Expression) { if(asmgen.options.slowCodegenWarnings) println("warning: slow stack evaluation used (3): @(${pointervar.nameInSource.last()}) $operator= ${value::class.simpleName} at ${value.position}") // TODO asmgen.translateExpression(value) val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) when (operator) { // note: ** (power) operator requires floats. - "+" -> asmgen.out(" clc | adc P8ESTACK_LO+1,x") - "-" -> asmgen.out(" sec | sbc P8ESTACK_LO+1,x") + "+" -> asmgen.out(" clc | adc P8ESTACK_LO+1,x") + "-" -> asmgen.out(" sec | sbc P8ESTACK_LO+1,x") "*" -> asmgen.out(" pha | lda P8ESTACK_LO+1,x | tay | pla | jsr math.multiply_bytes | ldy #0") "/" -> asmgen.out(" pha | lda P8ESTACK_LO+1,x | tay | pla | jsr math.divmod_ub_asm | tya | ldy #0") "%" -> asmgen.out(" pha | lda P8ESTACK_LO+1,x | tay | pla | jsr math.divmod_ub_asm | ldy #0") @@ -291,14 +291,14 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, asmgen.out(" inx") } - private fun inplaceModification_byte_variable_to_memory(pointervar: IdentifierReference, operator: String, value: IdentifierReference) { + private fun inplaceModification_byte_variable_to_pointer(pointervar: IdentifierReference, operator: String, value: IdentifierReference) { val otherName = asmgen.asmVariableName(value) val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) when (operator) { // note: ** (power) operator requires floats. - "+" -> asmgen.out(" clc | adc $otherName") - "-" -> asmgen.out(" sec | sbc $otherName") + "+" -> asmgen.out(" clc | adc $otherName") + "-" -> asmgen.out(" sec | sbc $otherName") "*" -> asmgen.out(" ldy $otherName | jsr math.multiply_bytes | ldy #0") "/" -> asmgen.out(" ldy $otherName | jsr math.divmod_ub_asm | tya | ldy #0") "%" -> asmgen.out(" ldy $otherName | jsr math.divmod_ub_asm | ldy #0") @@ -331,7 +331,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, asmgen.out(" sta (P8ZP_SCRATCH_W1),y") } - private fun inplaceModification_byte_litval_to_memory(pointervar: IdentifierReference, operator: String, value: Int) { + private fun inplaceModification_byte_litval_to_pointer(pointervar: IdentifierReference, operator: String, value: Int) { when (operator) { // note: ** (power) operator requires floats. "+" -> { diff --git a/docs/source/todo.rst b/docs/source/todo.rst index fd4134e06..f3a0f2912 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,6 +2,7 @@ TODO ==== +- check cpu stack consistency in all examples - reduce the amount of translateExpression() calls when the result can be directly assigned to register or variable - make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as '_' - option to load the built-in library files from a directory instead of the embedded ones (for easier library development/debugging) diff --git a/examples/test.p8 b/examples/test.p8 index 09468c7fa..11780cb14 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -8,17 +8,14 @@ main { uword uw = %1111111110000001 uword uw2 = %000111100001110 - ubyte ub = %00001110 + ubyte ub = 30 - uw &= ub + 1 - txt.print_uwbin(uw, 0) - txt.chrout('\n') - uw |= ub+1 - txt.print_uwbin(uw, 0) - txt.chrout('\n') + uword addr = $c000 - uw ^= ub+1 - txt.print_uwbin(uw, 0) + @(addr) = 0 + @(addr) ++ + @(addr) += 2*(ub+3) + txt.print_uw(@(addr)) txt.chrout('\n') testX()