From 9a6bd760bdbbdafaab7cd4afb72f368ae0d5113d Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 16 Mar 2021 23:40:32 +0100 Subject: [PATCH] fixed issues in uword '>' --- .../cpu6502/codegen/ExpressionsAsmGen.kt | 9 +- examples/test.p8 | 173 +++++++++--------- 2 files changed, 96 insertions(+), 86 deletions(-) diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt b/compiler/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt index a6e81e457..6e71b82a2 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt +++ b/compiler/src/prog8/compiler/target/cpu6502/codegen/ExpressionsAsmGen.kt @@ -622,17 +622,18 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge private fun translateUwordGreaterJump(left: Expression, right: Expression, leftConstVal: NumericLiteralValue?, rightConstVal: NumericLiteralValue?, jumpIfFalseLabel: String) { + // TODO verify correctness uword > + fun code(msbCpyOperand: String, lsbCmpOperand: String) { asmgen.out(""" cpy $msbCpyOperand - bcc $jumpIfFalseLabel + bcs $jumpIfFalseLabel bne + cmp $lsbCmpOperand - bcc $jumpIfFalseLabel - beq $jumpIfFalseLabel + bcs $jumpIfFalseLabel +""") - } + if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal<=leftConstVal) diff --git a/examples/test.p8 b/examples/test.p8 index 6c1a8a80f..1d27a18cc 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,177 +1,186 @@ %import textio -%zeropage basicsafe +%zeropage dontuse main { - sub start() { + ubyte num_files = 10 + + while num_files { + txt.print_ub(num_files) + txt.nl() + num_files-- + } + } + + sub start2() { txt.print("\n"*25) word xx word compare xx=10 - if xx>9 - txt.print("1ok\n") - else + if xx<9 txt.print("1fault\n") + else + txt.print("1ok\n") - if xx>10 + if xx<10 txt.print("2fault\n") else txt.print("2ok\n") - if xx>11 - txt.print("3fault\n") - else + if xx<11 txt.print("3ok\n") - - if xx>2222 - txt.print("4fault\n") else + txt.print("3fault\n") + + if xx<2222 txt.print("4ok\n") - - if xx>-9 - txt.print("5ok\n") else + txt.print("4fault\n") + + if xx<-9 txt.print("5fault\n") - - if xx>-9999 - txt.print("6ok\n") else + txt.print("5ok\n") + + if xx<-9999 txt.print("6fault\n") - - if xx>0 - txt.print("7ok\n") else + txt.print("6ok\n") + + if xx<0 txt.print("7fault\n") + else + txt.print("7ok\n") xx=0 - if xx>0 + if xx<0 txt.print("8false\n") else txt.print("8ok\n") xx=-9999 - if xx>0 - txt.print("9false\n") - else + if xx<0 txt.print("9ok\n") + else + txt.print("9fault\n") txt.nl() xx=10 compare=9 - if xx>compare - txt.print("1ok\n") - else + if xxcompare + if xxcompare - txt.print("3fault\n") - else + if xxcompare - txt.print("4fault\n") - else + if xxcompare - txt.print("5ok\n") - else + if xxcompare - txt.print("6ok\n") - else + if xxcompare - txt.print("7ok\n") - else + if xxcompare - txt.print("8false\n") + if xxcompare - txt.print("9false\n") - else + if xxcompare - txt.print("1ok\n") - else + xx=10 + compare=8 + if xxcompare + compare=9 + if xxcompare - txt.print("3fault\n") - else + compare=10 + if xxcompare - txt.print("4fault\n") - else + if xxcompare - txt.print("5ok\n") else + txt.print("4fault\n") + + compare=-8 + if xxcompare - txt.print("6ok\n") - else + if xxcompare - txt.print("7ok\n") else - txt.print("7fault\n") + txt.print("6ok\n") - xx=1 - if xx-1>compare - txt.print("8false\n") + compare=1 + if xxcompare - txt.print("9false\n") - else + if xx