From 10d0b03a90a62639f89025856a67fac4f1b650e7 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 3 Sep 2023 01:32:47 +0200 Subject: [PATCH] use less tempvars --- .../assignment/AugmentableAssignmentAsmGen.kt | 14 ++++++-------- docs/source/todo.rst | 1 - examples/test.p8 | 9 ++++----- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt index c4db483cc..f0e4fa047 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt @@ -2172,23 +2172,21 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, // the other variable is a BYTE type so optimize for that when (operator) { "+" -> { + // name += byteexpression if(valueDt==DataType.UBYTE) { - // TODO optimize: don't use scratch var - asmgen.assignExpressionToVariable(value, "P8ZP_SCRATCH_B1", valueDt) + asmgen.assignExpressionToRegister(value, RegisterOrPair.A, false) asmgen.out(""" - lda $name clc - adc P8ZP_SCRATCH_B1 + adc $name sta $name bcc + inc $name+1 +""") } else { - // TODO optimize: don't use scratch var - asmgen.assignExpressionToVariable(value, "P8ZP_SCRATCH_B1", valueDt) + asmgen.assignExpressionToRegister(value, RegisterOrPair.A, true) asmgen.out(""" ldy #0 - lda P8ZP_SCRATCH_B1 + cmp #0 bpl + dey ; sign extend + clc @@ -2200,7 +2198,7 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, } } "-" -> { - // TODO optimize: don't use scratch var + // name -= byteexpression asmgen.assignExpressionToVariable(value, "P8ZP_SCRATCH_B1", valueDt) if(valueDt==DataType.UBYTE) asmgen.out(""" diff --git a/docs/source/todo.rst b/docs/source/todo.rst index df8c618ef..4d759f123 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,7 +3,6 @@ TODO - fix on c64 target: examples/cube3d-float (broken since 9.3 with the evalstack removal) it works on x16 target, oddly enough. More detailed and simpler code for this problem in floatproblem64.p8 / floatproblem64.asm (the minified version) -- optimize: search for TODO optimize: don't use scratch var - prefix prog8 subroutines with p8s_ instead of p8_ to not let them clash with variables in the asm? - allow 'chained' array indexing for expressions: value = ptrarray[0][0] - allow 'chained' array indexing for assign targets: ptrarray[0][0] = 42 this is just evaluating the lhs as a uword pointer expression diff --git a/examples/test.p8 b/examples/test.p8 index e1e274e1b..cbf4d876f 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -4,11 +4,10 @@ main { sub start() { - uword ww= 300 - @($4000) = 100 - ww -= @($4000) - ww -= 100 - txt.print_uw(ww) ; 100 + byte bb = 20 + word ww= 300 + ww += bb*3 + txt.print_w(ww) ; 240 ; ubyte index = 100 ; ubyte[] t_index = [1,2,3,4,5]