Stack Suff
Stack Suff
So I'm relatively new at this whole "controlling the processor on a miniscule level where you can change things integral to the thing running properly" thing, and have a small question. Tutorials I've found never seem to have any problems with just shoving things into the stack, and I seem to be missing something since to me it seems absolutely absurd to even touch something so integral for functioning subroutines/JSR as that. Any idea what I might be missing here?
Re: Stack Suff
Welcome! You do have to be pretty careful with the stack: in between calls and returns you need to push and pop exactly the same number of bytes. But so long as you do that, you're fine - the stack is just some memory with automatic addressing, it doesn't know anything about what the data means.
Sometimes it's useful to be just a bit more involved: knowing what RTS is going to do, you can push two bytes and then RTS, and you've just something rather like a computed jump.
Hope this helps.
Sometimes it's useful to be just a bit more involved: knowing what RTS is going to do, you can push two bytes and then RTS, and you've just something rather like a computed jump.
Hope this helps.
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Stack Suff
There's a lot more power in the stack than meets the eye. You can do a load of things with it, and have lots of things pending, and as Ed said, as long you know what you're doing, nothing gets messed up. I have a treatise on 6502 stacks at http://wilsonminesco.com/stacks/ since forum posts showed the need for it. It addresses the range of subjects regarding stacks, starting with the definition and gradually reaching a stage a little bit past intermediate use, mostly ignoring the loftier subjects like multi-user, multithreading, and multitasking systems (which the 6502 is not very well suited for anyway).
Here's a list of chapters:
Start at the beginning and go as far as you're comfortable.
Happy programming!
Here's a list of chapters:
- definition and very basics
- subroutine return addresses and nesting
- interrupts
- virtual stacks and various ways to implement them
- stack addressing, both hardware and virtual
- passing parameters, and comparison of methods
- having a subroutine find inlined data, using the return address
- doing math and other operations by stacks in RPN
- RPN efficiency
- 65c02's added instructions that are useful in stacks
- using RTS, RTI, and JSR to synthesized other instructions
- where-am-I routines, for self-relocatable code
- a peek at the 65816's new instructions and capabilities that are relevant to stacks, and 65c02 code which partially synthesizes some of them
- local variables and environments
- recursion
- enough stack space?
- compiling or assembling program structures
- stack potpourri
- for further reading
Start at the beginning and go as far as you're comfortable.
Happy programming!
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: Stack Suff
The "virtual stacks" section and the advice from both of you helped, thanks! I was trying to use this as a graphics data buffer with the NES's VBLANK and NMI, and the tutorials I saw out there... aren't the best about this
- commodorejohn
- Posts: 299
- Joined: 21 Jan 2016
- Location: Placerville, CA
- Contact:
Re: Stack Suff
NESguy wrote:
I was trying to use this as a graphics data buffer with the NES's VBLANK and NMI, and the tutorials I saw out there... aren't the best about this
Still, it's a bit counter-intuitive and I'm not sure how much your typical NES game really needs to transfer in a single frame (especially since it's really only tilemap data and non-ROM tile definitions that are stored in main PPU RAM - the sprite table is separate and has its own DMA facility.)