From e1b3582f0886de8069e3d620a0f41395383352ab Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 3 Sep 2023 01:12:26 +0200 Subject: [PATCH] fix wordvar -= @(memory) --- .../assignment/AugmentableAssignmentAsmGen.kt | 6 ++-- examples/test.p8 | 28 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt index 9389d205c..c4db483cc 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt @@ -892,7 +892,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, // now implement the non-assiciative operators... when (operator) { "-" -> { - // TODO optimize: don't use scratch var + // A = variable - A val tmpVar = if(variable!="P8ZP_SCRATCH_B1") "P8ZP_SCRATCH_B1" else "P8ZP_SCRATCH_REG" asmgen.out(" sta $tmpVar | lda $variable | sec | sbc $tmpVar") } @@ -1240,8 +1240,8 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, +""") } "-" -> { + // name -= @(memory) asmgen.translateDirectMemReadExpressionToRegA(memread) - // TODO optimize: don't use scratch var if possible val tmpByte = if(name!="P8ZP_SCRATCH_B1") "P8ZP_SCRATCH_B1" else "P8ZP_SCRATCH_REG" asmgen.out(""" sta $tmpByte @@ -1249,7 +1249,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, sec sbc $tmpByte sta $name - bcc + + bcs + dec $name+1 +""") } diff --git a/examples/test.p8 b/examples/test.p8 index 0d728d72b..e1e274e1b 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -3,25 +3,25 @@ main { sub start() { - byte index = 100 - byte[] t_index = [-1,-2,-3,-4,-5] - index = 4 - index = index>t_index[4] - txt.print_b(index) - txt.nl() - index = index>t_index[4] - txt.print_b(index) - txt.nl() + uword ww= 300 + @($4000) = 100 + ww -= @($4000) + ww -= 100 + txt.print_uw(ww) ; 100 -; index = index < t_index[4] -; index = index < t_index[nibble] -; txt.print_ub(index) +; ubyte index = 100 +; ubyte[] t_index = [1,2,3,4,5] +; ubyte nibble = 0 +; +; index = index + t_index[4] +; index = index + t_index[nibble] +; txt.print_ub(index) ; 106 ; txt.nl() ; ; nibble++ -; index = index > t_index[3] -; index = index > t_index[nibble] +; index = index - t_index[3] +; index = index - t_index[nibble] ; txt.print_ub(index) ; 100 ; txt.nl() }