Another one to add even to the NMOS part is removing the CMP #0 after anything affecting the accumulator, or the CPY #0 after anything affecting Y, or the CPX #0 after anything affecting X.
This is quite obvious, not even an "optimisation".
Totally agreed; but the waste of these instructions is epidemic. One person posting there recently said he just wanted to make the code more clear (which it does not do).
I'm working on a 6502-targeted compiler, which is generating a lot of STA/LDA to the same location, so I plan to write some sort of peep-hole optimizer. I've decided to use straight BRx instructions in the IF/ELSE structures, even though that will limit the number of instructions in the blocks, because they are so common. FOR/WHILE/DO loops will use BRx/JMP combinations.
For doing an in-range test, instead of testing both the low bound & high bound, offset it so the range starts at 0 and do an unsigned test with the high bound.
As long as you don't need to preserve the accumulator, of course
White Flame wrote:
For doing an in-range test, instead of testing both the low bound & high bound, offset it so the range starts at 0 and do an unsigned test with the high bound.