diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/ExpressionsAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/ExpressionsAsmGen.kt index 877005e2e..3473feae1 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/ExpressionsAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/ExpressionsAsmGen.kt @@ -798,7 +798,8 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge "<=" -> asmgen.out(if(dt==DataType.UWORD) " jsr prog8_lib.lesseq_uw" else " jsr prog8_lib.lesseq_w") ">=" -> asmgen.out(if(dt==DataType.UWORD) " jsr prog8_lib.greatereq_uw" else " jsr prog8_lib.greatereq_w") "==" -> asmgen.out(" jsr prog8_lib.equal_w") - "!=" -> asmgen.out(" jsr prog8_lib.notequal_w") "&" -> asmgen.out(" jsr prog8_lib.bitand_w") + "!=" -> asmgen.out(" jsr prog8_lib.notequal_w") + "&" -> asmgen.out(" jsr prog8_lib.bitand_w") "^" -> asmgen.out(" jsr prog8_lib.bitxor_w") "|" -> asmgen.out(" jsr prog8_lib.bitor_w") "and" -> asmgen.out(" jsr prog8_lib.and_w") diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt index e8bff62ad..5a8dcfcd1 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt @@ -1066,6 +1066,18 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, else asmgen.out(" lda #0 | sta $name | sta $name+1") } + value == 0x00ff -> { + if(asmgen.isTargetCpu(CpuType.CPU65c02)) + asmgen.out(" stz $name+1") + else + asmgen.out(" lda #0 | sta $name+1") + } + value == 0xff00 -> { + if(asmgen.isTargetCpu(CpuType.CPU65c02)) + asmgen.out(" stz $name") + else + asmgen.out(" lda #0 | sta $name") + } value and 255 == 0 -> { if(asmgen.isTargetCpu(CpuType.CPU65c02)) asmgen.out(" stz $name") diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 828d080aa..7af4a0d97 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,6 +3,10 @@ TODO For next release ^^^^^^^^^^^^^^^^ +- fix optimization of w >>= 8 , it generates bad code when opt=on, ok when opt=off +- fix w <<= 8 generates weird code with pha/pla in it when opt=on, ok when opt=off +- optimize w=msb(w) => w >>=8, w=lsb(w) ==> w &= $00ff + fix the value of ww being wrong (with optimizations enabled) in : sub start() { byte ub1 = -50 @@ -17,7 +21,6 @@ fix the value of ww being wrong (with optimizations enabled) in : return x1 } -- optimize w=msb(w), w=lsb(w) ... @@ -37,7 +40,7 @@ Blocked by an official Commander-x16 r39 release Future Things and Ideas ^^^^^^^^^^^^^^^^^^^^^^^ -- nameInAssemblyCode() should search smarter +- nameInAssemblyCode() should search smarter (only labels in column 0? only full words, not part of a larger word?) - Fix: don't report as recursion if code assigns address of its own subroutine to something, rather than calling it - allow "xxx" * constexpr (where constexpr is not a number literal, now gives expression error not same type) - can we promise a left-to-right function call argument evaluation? without sacrificing performance diff --git a/examples/test.p8 b/examples/test.p8 index 3c87986a6..c2871da29 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,23 +1,25 @@ %import textio -%import string %zeropage basicsafe main { sub start() { - uword xx=$ea31 - xx = lsb(xx) - uword ww = plot(lsb(xx), msb(xx)) - ww=msb(ww) - txt.print_uwhex(ww, true) + uword @shared xx=$ea31 + xx &= $00ff + ;xx = lsb(xx) + txt.print_uwhex(xx, true) + xx = $ea31 + xx &= $ff00 + ; xx = msb(xx) +; %asm {{ +; nop +; nop +; }} +; xx >>= 8 +; %asm {{ +; nop +; nop +; }} +; xx <<= 8 + txt.print_uwhex(xx, true) } - - inline asmsub plot(uword plotx @R0, uword ploty @R1) -> uword @AY{ - %asm {{ - lda cx16.r0 - ldy cx16.r1 - rts - }} - } - - }