I have a lot of tips of this kind in the Tips For Programming the 65(c )02 chapter of my 6502 primer. The following is one of them.
An automatic compare-to-zero instruction is built into the following 65(C )02 instructions: LDA, LDX, LDY, INC, INX, INY, DEC, DEX, DEY, INA, DEA, AND, ORA, EOR, ASL, LSR, ROL, ROR, PLA, PLX, PLY, SBC, ADC, TAX, TXA, TAY, TYA, and TSX. This means that, for example, a CMP #0 after an LDA is redundant, a wasted instruction. The only time a 65c02 (CMOS) needs a compare-to-zero instruction after one of these is if you want to compare a register that was not involved in the previous instruction; for example,
CPX #0 (Note the Y and the X are not the same register.) If you can spare a register to which you can transfer the one you want to test, you can save a byte with the transfer instead of a compare instruction. The example above, if the contents of A don't need to be kept, could be changed to:
TXA and then you can branch on the N or Z flag which tell if X was negative or zero. The TXA isn't any faster (both TXA and CPX# take two clocks); but TXA takes only one byte, whereas the CPX #0 takes two bytes.
The NMOS 6502 did have a bug in that the flags weren't always correct after a decimal-mode operation like ADC; so then you might have to follow it with the CMP #0 to get the N and Z flags right. It's best to just use the CMOS processor when possible.
Note to admin: I have PM'ed about this kind of thing before, and gotten no answer. Whether in BBCode mode or otherwise, I can't find any way to keep the "#0" black in the code section, or put the C in 65C02 in parentheses without a space after it and keep it from turning it into the copyright sign, or other things I want to do. In BBCode mode, there's no line wrap as I'm writing. This kind of thing is why I don't post much on this forum. It's too discouraging. Please give the option to just do like the phpBB forums where we manually tell it everything we want, or even html as done in a plain text editor where we manually write all the tags..