Dr Jefyll wrote:
More specifically, in a case where only a handful of bytes are needed, it's faster to adjust the stack pointer simply by coding some dummy pushes or pulls. By "dummy" I mean the data transferred to or from memory is "don't care" and will be discarded -- the actual goal is merely to increment or decrement S.
Right. I think I once figured out that the "break even" point on the '816 for where arithmetic adjustment of the stack pointer was faster than dummy pushes was at 5 bytes.
Quote:
It's only appropriate in certain cases. Dummy
pulls can be awkward, since the data transfer can't be avoided and may destroy a register you'd prefer to keep. (But the general technique destroys a register, too, so it's a wash.)
A dummy push only destroys some memory space that's undefined anyway. And, if you're clever, the value pushed will be not garbage to be overwritten but instead something the following code can actually use. If you haven't already, check out the PEA PEI and PER instructions.
I often use PEA #0 to generate and initialize stack space, even if I need an odd number of bytes. It also allows me the leave the registers untouched. PEI is useful if an initial 16 bit value needed on the stack is already sitting on direct page. PER's only real value is to set up an address relative to PC. It's slower than the other two, so I don't see it as a particularly good way to reserve and initialize stack space.
As you note, there's no way to avoid clobbering a register to release stack space. Either it will be done via pulls or arithmetically. Fortunately. with the '816 only the accumulator is needed to arithmetically adjust SP.