fix for loop with signed byte loopvar over non-const

This commit is contained in:
Irmen de Jong 2020-11-20 22:54:24 +01:00
parent afd155ac4f
commit fefd9b52a8
2 changed files with 27 additions and 26 deletions

View File

@ -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("""
lda $varname
clc
adc #$stepsize
sta $varname
$modifiedLabel cmp #0 ; modified
bcc $loopLabel
bmi $loopLabel
beq $loopLabel""")
} else {
asmgen.out("""
lda $varname
sec
sbc #${stepsize.absoluteValue}
sta $varname
$modifiedLabel cmp #0 ; modified
bcs $loopLabel""")
bpl $loopLabel""")
}
asmgen.out(endLabel)
}

View File

@ -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')