I was playing with Ed Snider's CoCo PSG. The CoCo PSG has a built in audio out jack which is great but I wanted to output the sound from his cartridge to the regular outputs on the CoCo (RF and Audio out on the CoCo3). According to the CoCo PSG User's Manual it does support outputting sound through the regualr CoCo audio output ports so I was looking through some documents to set the source to the cartridge port by doing the following:

This is a cool little trick, if you want to set A to 0 then jump to LA974 if you want A to equal 8 jump to LA976. You don't need to have a BRA after the CLRA instruction if you use FCB $8C, before today I would have written the same bit of code in a longer method as:

So in this example you've inserted opcode $8C (CMPX immediate addressing mode) meaning the following two bytes, LDA #08, are interpreted as the operand.

That's an interesting memory optimisation I hadn't considered before although I should say CMPX #$xxxx takes 4 cycles whereas BRA Skip is only 3, so unfortunately not a performance saving.

That said, when clearing the 16-bit accumulator I generally use CLRA+CLRB to save a memory byte and LDD #$0000 only when cycle count is critical eg. during render routines.

Saving a byte doesn't sound a lot but it soon mounts up. A friend of mine recently reminded me of the importance of using DP addressing for things like game variables etc. Not only is it faster but he calculated he had saved approx. 600 bytes just by using DP instead of Extended addressing, which on a 32k total machine like the Dragon is quite significant.

Yeah you're correct it doesn't actually make it faster but slower but if you need to squeeze your code into a certain size it is a neat little trick. Yeah using the DP can really help speed wise and space too.