mirror of
https://github.com/irmen/prog8.git
synced 2024-12-27 20:33:39 +00:00
added (u)byte and (u)word '>'
This commit is contained in:
parent
130cee1e70
commit
43f2448789
@ -276,7 +276,6 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
|
||||
private fun translateUbyteLessOrEqual(left: Expression, right: Expression, leftConstVal: NumericLiteralValue?, rightConstVal: NumericLiteralValue?, jumpIfFalseLabel: String) {
|
||||
// TODO compare with optimized asm
|
||||
TODO()
|
||||
asmgen.translateExpression(left)
|
||||
asmgen.translateExpression(right)
|
||||
asmgen.out(" jsr prog8_lib.lesseq_ub | inx | lda P8ESTACK_LO,x | beq $jumpIfFalseLabel")
|
||||
@ -318,13 +317,16 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
cmp #${rightConstVal.number}
|
||||
bcc $jumpIfFalseLabel
|
||||
beq $jumpIfFalseLabel""")
|
||||
else
|
||||
asmgen.out(" lda $name | beq $jumpIfFalseLabel")
|
||||
return
|
||||
}
|
||||
else if (left is DirectMemoryRead) {
|
||||
if(rightConstVal.number.toInt()!=0) {
|
||||
translateDirectMemReadExpression(left, false)
|
||||
translateDirectMemReadExpression(left, false)
|
||||
if(rightConstVal.number.toInt()!=0)
|
||||
asmgen.out(" cmp #${rightConstVal.number} | bcc $jumpIfFalseLabel | beq $jumpIfFalseLabel")
|
||||
}
|
||||
else
|
||||
asmgen.out(" beq $jumpIfFalseLabel")
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -336,21 +338,106 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
}
|
||||
|
||||
private fun translateByteGreater(left: Expression, right: Expression, leftConstVal: NumericLiteralValue?, rightConstVal: NumericLiteralValue?, jumpIfFalseLabel: String) {
|
||||
// TODO compare with optimized asm
|
||||
if(rightConstVal!=null) {
|
||||
if(leftConstVal!=null) {
|
||||
if(rightConstVal<=leftConstVal)
|
||||
asmgen.out(" jmp $jumpIfFalseLabel")
|
||||
return
|
||||
} else {
|
||||
if (left is IdentifierReference) {
|
||||
val name = asmgen.asmVariableName(left)
|
||||
if(rightConstVal.number.toInt()!=0)
|
||||
asmgen.out("""
|
||||
lda $name
|
||||
cmp #${rightConstVal.number}
|
||||
bmi $jumpIfFalseLabel
|
||||
beq $jumpIfFalseLabel""")
|
||||
else
|
||||
asmgen.out("""
|
||||
lda $name
|
||||
bmi $jumpIfFalseLabel
|
||||
beq $jumpIfFalseLabel""")
|
||||
return
|
||||
}
|
||||
else if (left is DirectMemoryRead) {
|
||||
translateDirectMemReadExpression(left, false)
|
||||
if(rightConstVal.number.toInt()!=0)
|
||||
asmgen.out(" cmp #${rightConstVal.number} | bmi $jumpIfFalseLabel | beq $jumpIfFalseLabel")
|
||||
else
|
||||
asmgen.out(" bmi $jumpIfFalseLabel | beq $jumpIfFalseLabel")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
asmgen.translateExpression(left)
|
||||
asmgen.translateExpression(right)
|
||||
asmgen.out(" jsr prog8_lib.greater_b | inx | lda P8ESTACK_LO,x | beq $jumpIfFalseLabel")
|
||||
}
|
||||
|
||||
private fun translateUwordGreater(left: Expression, right: Expression, leftConstVal: NumericLiteralValue?, rightConstVal: NumericLiteralValue?, jumpIfFalseLabel: String) {
|
||||
// TODO compare with optimized asm
|
||||
if(rightConstVal!=null) {
|
||||
if(leftConstVal!=null) {
|
||||
if(rightConstVal>=leftConstVal)
|
||||
asmgen.out(" jmp $jumpIfFalseLabel")
|
||||
return
|
||||
} else {
|
||||
if (left is IdentifierReference) {
|
||||
val name = asmgen.asmVariableName(left)
|
||||
if(rightConstVal.number.toInt()!=0)
|
||||
asmgen.out("""
|
||||
lda $name+1
|
||||
cmp #>${rightConstVal.number}
|
||||
bcc $jumpIfFalseLabel
|
||||
bne +
|
||||
lda $name
|
||||
cmp #<${rightConstVal.number}
|
||||
bcc $jumpIfFalseLabel
|
||||
beq $jumpIfFalseLabel
|
||||
+""")
|
||||
else
|
||||
asmgen.out("""
|
||||
lda $name
|
||||
bne +
|
||||
lda $name+1
|
||||
beq $jumpIfFalseLabel
|
||||
+""")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
asmgen.translateExpression(left)
|
||||
asmgen.translateExpression(right)
|
||||
asmgen.out(" jsr prog8_lib.greater_uw | inx | lda P8ESTACK_LO,x | beq $jumpIfFalseLabel")
|
||||
}
|
||||
|
||||
private fun translateWordGreater(left: Expression, right: Expression, leftConstVal: NumericLiteralValue?, rightConstVal: NumericLiteralValue?, jumpIfFalseLabel: String) {
|
||||
// TODO compare with optimized asm
|
||||
if(rightConstVal!=null) {
|
||||
if(leftConstVal!=null) {
|
||||
if(rightConstVal<=leftConstVal)
|
||||
asmgen.out(" jmp $jumpIfFalseLabel")
|
||||
return
|
||||
} else {
|
||||
if (left is IdentifierReference) {
|
||||
val name = asmgen.asmVariableName(left)
|
||||
if(rightConstVal.number.toInt()!=0)
|
||||
asmgen.out("""
|
||||
lda $name
|
||||
cmp #<${rightConstVal.number}
|
||||
lda $name+1
|
||||
sbc #>${rightConstVal.number}
|
||||
bvc +
|
||||
eor #$80
|
||||
+ bmi $jumpIfFalseLabel
|
||||
beq $jumpIfFalseLabel""")
|
||||
else
|
||||
asmgen.out(" lda $name+1 | bmi $jumpIfFalseLabel | beq $jumpIfFalseLabel")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
asmgen.translateExpression(left)
|
||||
asmgen.translateExpression(right)
|
||||
asmgen.out(" jsr prog8_lib.greater_w | inx | lda P8ESTACK_LO,x | beq $jumpIfFalseLabel")
|
||||
|
@ -253,15 +253,15 @@ main {
|
||||
}
|
||||
|
||||
if uww>0 {
|
||||
txt.print("ok 8b\n")
|
||||
txt.print("ok 8k\n")
|
||||
} else {
|
||||
txt.print("fail 8b\n")
|
||||
txt.print("fail 8k\n")
|
||||
}
|
||||
|
||||
if uww>2222 {
|
||||
txt.print("fail 8b\n")
|
||||
txt.print("fail 8l\n")
|
||||
} else {
|
||||
txt.print("ok 8b\n")
|
||||
txt.print("ok 8l\n")
|
||||
}
|
||||
|
||||
; @($c000) *= 99 ; TODO implement
|
||||
|
Loading…
Reference in New Issue
Block a user