[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cc65 assembler stack usage?



On Friday, 7 June 2013 03:13:43 UTC+10, Harry Potter  wrote:
> In cc65 assembler, I know that sp is the pointer to the top of the stack.  I also know that pusha and pushax push a byte or word onto the stack, respectively, and popa and popax pop.  I also know that pusha0 zero-extends the .A to a word before pushing.  I know that push0-9 push constants to the stack.  But what about reading a parameter or auto variable inside a function?  I'm sure there's a better method than setting the .Y then offseting an access as in (sp),y when accessing words.

No, that's the way it's done. The cc65 parameter stack isn't the 6502 hardware stack, which is too small for parameters and variables so is used only for return addresses.

If by 'better' you mean 'fast', the way to go is to copy any frequently used parameters into a zero page location and reference them there directly. Inside cc65 code, this can be achieved by declaring an automatic variable as a register variable, provided you don't exceed 6 bytes of 'register' space in the function. 

Matt