more ifexpression codegen tweaks

This commit is contained in:
Irmen de Jong 2024-10-25 22:52:26 +02:00
parent 84d9040b57
commit 97b8cb748d
3 changed files with 41 additions and 15 deletions

View File

@ -417,6 +417,33 @@ internal class IfElseAsmGen(private val program: PtProgram,
}
}
if(constValue!=0) {
// TODO reuse more code from regular if statements. Need a shared routine like isWordExprEqualNumber() ?
when(condition.operator) {
"==" -> {
// if w==number
asmgen.assignExpressionToRegister(condition.left, RegisterOrPair.AY, signed)
asmgen.out("""
cmp #<$constValue
bne $falseLabel
cpy #>$constValue
bne $falseLabel""")
return
}
"!=" -> {
// if w!=number
asmgen.assignExpressionToRegister(condition.left, RegisterOrPair.AY, signed)
asmgen.out("""
cmp #<$constValue
bne +
cpy #>$constValue
beq $falseLabel
+""")
return
}
}
}
// TODO don't store condition as expression result but just use the flags, like a normal PtIfElse translation does
assignConditionValueToRegisterAndTest(condition)
asmgen.out(" beq $falseLabel")

View File

@ -1,4 +1,5 @@
; Routines to load and save "BMX" files (commander X16 bitmap format) Version 1.
; Bitmap data is loaded directly into VRAM without intermediary buffering.
; Only uncompressed images are supported for now.
; BMX Specification: https://cx16forum.com/forum/viewtopic.php?t=6945

View File

@ -5,21 +5,19 @@
main {
sub start() {
byte @shared ww = -99
ww++
if ww&1 ==0
txt.print("x ")
if ww&64 ==0
txt.print("a ")
if ww&128!=0
txt.print("neg ")
txt.print_ub(if ww & 64==0 111 else 222)
txt.spc()
txt.print_ub(if ww & 128!=0 111 else 222)
word @shared ww = 11111
txt.print_ub(if ww==11111 111 else 222)
txt.spc()
txt.print_ub(if ww!=11111 111 else 222)
txt.nl()
if ww==11111
txt.print("one\n")
else
txt.print("two\n")
if ww!=11111
txt.print("one\n")
else
txt.print("two\n")
}
}