diff --git a/compiler/src/prog8/compiler/target/c64/AsmPatterns.kt b/compiler/src/prog8/compiler/target/c64/AsmPatterns.kt index de6a1b801..e5a18722b 100644 --- a/compiler/src/prog8/compiler/target/c64/AsmPatterns.kt +++ b/compiler/src/prog8/compiler/target/c64/AsmPatterns.kt @@ -2066,7 +2066,20 @@ internal val patterns = listOf( AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CMP_B), listOf(Opcode.PUSH_VAR_BYTE, Opcode.CMP_UB)) { segment -> // this pattern is encountered as part of the loop bound condition in for loops (var + cmp + jz/jnz) val cmpval = segment[1].arg!!.integerValue() - " lda ${segment[0].callLabel} | cmp #$cmpval " + when(segment[0].callLabel) { + "A" -> { + " cmp #$cmpval " + } + "X" -> { + " cpx #$cmpval " + } + "Y" -> { + " cpy #$cmpval " + } + else -> { + " lda ${segment[0].callLabel} | cmp #$cmpval " + } + } }, AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CMP_W), listOf(Opcode.PUSH_VAR_WORD, Opcode.CMP_UW)) { segment -> // this pattern is encountered as part of the loop bound condition in for loops (var + cmp + jz/jnz) diff --git a/examples/test.p8 b/examples/test.p8 index b979d352b..6e15b9669 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -4,17 +4,13 @@ ~ main { sub start() { - A=0 - Y=0 - ubyte aa =0 - - Y=10 - for A in 0 to 4 { for Y in 0 to 3 { rsave() c64scr.print_ub(A) c64.CHROUT(',') + rrestore() + rsave() c64scr.print_ub(Y) c64.CHROUT('\n') rrestore()