diff --git a/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt b/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt index a7a2c8eb5..5a3e8c7a6 100644 --- a/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt +++ b/codeGeneration/src/prog8/codegen/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt @@ -574,6 +574,26 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, asmgen.assignExpressionToRegister(value, RegisterOrPair.A) asmgen.out(" eor $name | sta $name") } + "==" -> { + asmgen.assignExpressionToRegister(value, RegisterOrPair.A) + asmgen.out(""" + cmp $name + beq + + lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } + "!=" -> { + asmgen.assignExpressionToRegister(value, RegisterOrPair.A) + asmgen.out(""" + cmp $name + beq + + lda #1 + bne ++ ++ lda #0 ++ sta $name""") + } else -> throw AssemblyError("invalid operator for in-place modification $operator") } } @@ -631,6 +651,26 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, "&", "and" -> asmgen.out(" lda $name | and $otherName | sta $name") "|", "or" -> asmgen.out(" lda $name | ora $otherName | sta $name") "^", "xor" -> asmgen.out(" lda $name | eor $otherName | sta $name") + "==" -> { + asmgen.out(""" + lda $otherName + cmp $name + beq + + lda #0 + bne ++ ++ lda #1 ++ sta $name""") + } + "!=" -> { + asmgen.out(""" + lda $otherName + cmp $name + beq + + lda #1 + bne ++ ++ lda #0 ++ sta $name""") + } else -> throw AssemblyError("invalid operator for in-place modification $operator") } } @@ -702,6 +742,26 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, "&", "and" -> asmgen.out(" lda $name | and #$value | sta $name") "|", "or" -> asmgen.out(" lda $name | ora #$value | sta $name") "^", "xor" -> asmgen.out(" lda $name | eor #$value | sta $name") + "==" -> { + asmgen.out(""" + lda #$value + cmp $name + beq + + lda #0 + bne ++ ++ lda #1 ++ sta $name""") + } + "!=" -> { + asmgen.out(""" + lda #$value + cmp $name + beq + + lda #1 + bne ++ ++ lda #0 ++ sta $name""") + } else -> throw AssemblyError("invalid operator for in-place modification $operator") } } diff --git a/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt b/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt index be706c5f1..531ea4494 100644 --- a/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt +++ b/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt @@ -448,8 +448,6 @@ internal class StatementReorderer(val program: Program, return noModifications } else { // clobber risk; evaluate the arguments on the CPU stack first (in reverse order)... - if (options.slowCodegenWarnings) - errors.warn("slow argument passing used to avoid register clobbering", call.position) val argOrder = options.compTarget.asmsubArgsEvalOrder(function) val scope = AnonymousScope(mutableListOf(), call.position) if(function.shouldSaveX()) { diff --git a/examples/test.p8 b/examples/test.p8 index 8c1e98d10..fa34c500e 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -3,11 +3,13 @@ main { sub start() { - ubyte xx - ubyte yy + ubyte @shared xx + ubyte @shared yy - if xx==0 or xx==4 { + yy = xx==7 + if xx==99 { xx++ + yy++ } txt.nl() }