diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmOptimizer.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmOptimizer.kt index 9a313ceaf..d4c6e3cc4 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmOptimizer.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmOptimizer.kt @@ -64,6 +64,10 @@ fun optimizeAssembly(lines: MutableList, machine: IMachineDefinition, pr return numberOfOptimizations } +private fun String.isBranch() = this.startsWith("b") +private fun String.isStoreReg() = this.startsWith("sta") || this.startsWith("sty") || this.startsWith("stx") +private fun String.isLoadReg() = this.startsWith("lda") || this.startsWith("ldy") || this.startsWith("ldx") + private class Modification(val lineIndex: Int, val remove: Boolean, val replacement: String?) private fun apply(modifications: List, lines: MutableList) { @@ -196,9 +200,9 @@ private fun optimizeSameAssignments(linesByFourteen: List4) { val firstvalue = first.substring(4) val secondvalue = second.substring(4) @@ -296,7 +300,7 @@ private fun optimizeSameAssignments(linesByFourteen: List>>, ) { val third = lines[3].value.trimStart() val attemptRemove = - if(third.startsWith("b")) { + if(third.isBranch()) { // a branch instruction follows, we can only remove the load instruction if // another load instruction of the same register precedes the store instruction // (otherwise wrong cpu flags are used)