diff --git a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt index 5c40c4d59..10f746edf 100644 --- a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt @@ -94,7 +94,26 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge } } DataType.BYTE, DataType.WORD -> { - TODO("signed BYTE/UWORD comparison $operator") + if(dt==DataType.BYTE) { + asmgen.assignExpressionToRegister(left, RegisterOrPair.A) + if (left is FunctionCall && !left.isSimple) + asmgen.out(" cmp #0") + } else { + asmgen.assignExpressionToRegister(left, RegisterOrPair.AY) + asmgen.out(" sty P8ZP_SCRATCH_B1 | ora P8ZP_SCRATCH_B1") // TODO PROBABLY NOT OKAY FOR WORDS + } + when (operator) { + "==" -> asmgen.out(" bne $jumpIfFalseLabel") + "!=" -> asmgen.out(" beq $jumpIfFalseLabel") + ">" -> asmgen.out(" beq $jumpIfFalseLabel | bmi $jumpIfFalseLabel") + "<" -> asmgen.out(" bpl $jumpIfFalseLabel") + ">=" -> asmgen.out(" bmi $jumpIfFalseLabel") + "<=" -> asmgen.out(""" + beq + + bpl $jumpIfFalseLabel + + """) + else -> throw AssemblyError("invalid comparison operator $operator") + } } DataType.FLOAT -> { asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1) diff --git a/examples/test.p8 b/examples/test.p8 index 628a9dba1..3cc40bfb6 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -4,7 +4,7 @@ main { sub start() { - ubyte xx + byte xx xx=0 @@ -16,7 +16,7 @@ main { if xx<=0 { txt.print("xx<=0\n") } else { - txt.print("error1\n") + txt.print("error1qq\n") } if xx>0 { txt.print("xx>0 error\n") @@ -53,27 +53,27 @@ main { } txt.nl() -; xx=-11 -; if xx>=0 { -; txt.print("xx>=0 error\n") -; } else { -; txt.print("ok3\n") -; } -; if xx<=0 { -; txt.print("xx<=0\n") -; } else { -; txt.print("error3\n") -; } -; if xx>0 { -; txt.print("xx>0 error\n") -; } else { -; txt.print("ok3\n") -; } -; if xx<0 { -; txt.print("xx<0\n") -; } else { -; txt.print("error3\n") -; } + xx=-11 + if xx>=0 { + txt.print("xx>=0 error\n") + } else { + txt.print("ok3\n") + } + if xx<=0 { + txt.print("xx<=0\n") + } else { + txt.print("error3\n") + } + if xx>0 { + txt.print("xx>0 error\n") + } else { + txt.print("ok3\n") + } + if xx<0 { + txt.print("xx<0\n") + } else { + txt.print("error3\n") + }