mirror of
https://github.com/irmen/prog8.git
synced 2024-11-30 08:52:30 +00:00
optimize add/sub expr
This commit is contained in:
parent
6db715d879
commit
6c233c6a0a
@ -529,7 +529,18 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
||||
assignRegisterByte(assign.target, CpuRegister.A, dt in SignedDatatypes)
|
||||
return true
|
||||
}
|
||||
else -> return false
|
||||
else -> {
|
||||
assignExpressionToRegister(left, RegisterOrPair.A, left.type==DataType.BYTE)
|
||||
asmgen.out(" pha")
|
||||
assignExpressionToVariable(right, "P8ZP_SCRATCH_B1", right.type)
|
||||
asmgen.out(" pla")
|
||||
if(expr.operator=="+")
|
||||
asmgen.out(" clc | adc P8ZP_SCRATCH_B1")
|
||||
else
|
||||
asmgen.out(" sec | sbc P8ZP_SCRATCH_B1")
|
||||
assignRegisterByte(assign.target, CpuRegister.A, dt in SignedDatatypes)
|
||||
return true
|
||||
}
|
||||
}
|
||||
} else if(dt in WordDatatypes) {
|
||||
when (right) {
|
||||
@ -630,7 +641,30 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> return false
|
||||
else -> {
|
||||
assignExpressionToVariable(right, "P8ZP_SCRATCH_W2", right.type)
|
||||
assignExpressionToRegister(left, RegisterOrPair.AY, left.type==DataType.WORD)
|
||||
if(expr.operator=="+")
|
||||
asmgen.out("""
|
||||
clc
|
||||
adc P8ZP_SCRATCH_W2
|
||||
pha
|
||||
tya
|
||||
adc P8ZP_SCRATCH_W2+1
|
||||
tay
|
||||
pla""")
|
||||
else
|
||||
asmgen.out("""
|
||||
sec
|
||||
sbc P8ZP_SCRATCH_W2
|
||||
pha
|
||||
tya
|
||||
sbc P8ZP_SCRATCH_W2+1
|
||||
tay
|
||||
pla""")
|
||||
assignRegisterpairWord(assign.target, RegisterOrPair.AY)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,31 +3,13 @@
|
||||
|
||||
main {
|
||||
|
||||
uword vv = 60
|
||||
|
||||
sub print_time(uword seconds) {
|
||||
ubyte remainder = seconds % $0003 ==0
|
||||
txt.print_uw(remainder)
|
||||
txt.nl()
|
||||
}
|
||||
|
||||
sub print_time2(ubyte seconds) {
|
||||
ubyte remainder = seconds % 3 ==0
|
||||
txt.print_uw(remainder)
|
||||
txt.nl()
|
||||
}
|
||||
|
||||
word[5] dx = [111,222,333,444,555]
|
||||
|
||||
sub start() {
|
||||
print_time(9870)
|
||||
print_time(9871)
|
||||
print_time(9872)
|
||||
print_time(9873)
|
||||
txt.nl()
|
||||
print_time2(50)
|
||||
print_time2(51)
|
||||
print_time2(52)
|
||||
print_time2(53)
|
||||
uword hit_x = 999
|
||||
cx16.r0=2
|
||||
uword new_head_x = hit_x + dx[cx16.r0L] as uword
|
||||
txt.print_uw(new_head_x)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user