diff --git a/compiler/src/prog8/compiler/target/c64/codegen/ForLoopsAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/ForLoopsAsmGen.kt index b44151931..be750f2ab 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/ForLoopsAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/ForLoopsAsmGen.kt @@ -54,11 +54,11 @@ internal class ForLoopsAsmGen(private val program: Program, private val asmgen: asmgen.out(loopLabel) asmgen.translate(stmt.body) asmgen.out(""" - lda $varname -$modifiedLabel cmp #0 ; modified - beq $endLabel - $incdec $varname - jmp $loopLabel + lda $varname +$modifiedLabel cmp #0 ; modified + beq $endLabel + $incdec $varname + jmp $loopLabel $endLabel""") } else { @@ -71,22 +71,23 @@ $endLabel""") asmgen.assignExpressionToVariable(range.to, "$modifiedLabel+1", ArrayElementTypes.getValue(iterableDt), null) asmgen.out(loopLabel) asmgen.translate(stmt.body) - asmgen.out(" lda $varname") if(stepsize>0) { asmgen.out(""" - clc - adc #$stepsize - sta $varname -$modifiedLabel cmp #0 ; modified - bcc $loopLabel - beq $loopLabel""") + lda $varname + clc + adc #$stepsize + sta $varname +$modifiedLabel cmp #0 ; modified + bmi $loopLabel + beq $loopLabel""") } else { asmgen.out(""" - sec - sbc #${stepsize.absoluteValue} - sta $varname -$modifiedLabel cmp #0 ; modified - bcs $loopLabel""") + lda $varname + sec + sbc #${stepsize.absoluteValue} + sta $varname +$modifiedLabel cmp #0 ; modified + bpl $loopLabel""") } asmgen.out(endLabel) } diff --git a/examples/test.p8 b/examples/test.p8 index d2e3022e3..d5fa05c55 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -12,10 +12,10 @@ main { uword uw word ww - ubyte arrub = 10 - uword arruw = 10 - byte arrb = 10 - word arrw = 10 + const ubyte arrub = 10 + const uword arruw = 10 + const byte arrb = 10 + const word arrw = 10 test_stack.test() @@ -73,11 +73,11 @@ main { } txt.chrout('\n') - for ww in arrw-2 to -2 step -2 { - txt.print_w(ww) - txt.chrout(',') - } - txt.chrout('\n') +; for ww in arrw-2 to -2 step -2 { +; txt.print_w(ww) +; txt.chrout(',') +; } +; txt.chrout('\n') test_stack.test() txt.chrout('\n')