home   |   stacks treatise index   |   1. Intro: stack basics   |   2. subroutine return addresses & nesting   |   3. interrupts   |   4. virtual stacks   |   5. stack addressing   |   6. passing parameters   |   7. inlined data   |   8. RPN operations   |   9. RPN efficiency   |   10. 65c02 added instructions   |   11. synth instructions w/ RTS/RTI/JSR   |   12. where-am-I routines   |   13. synthesizing 65816 stack instructions   |   14. local variables, environments   |   15. recursion   |   16. enough stack space?   |   17. forming program structures   |   18. stack potpourri   |   19. further reading   |   A: StackOps.ASM   |   B: 816StackOps.ASM   |   Appendix C


6502 STACKS TREATISE


For further reading

6502.org forum topics:
Stack Frames
Extra Stacks
65C816 PROGRAMMING TIPS & TRICKS
M65C02A: Stack Pointer Relative vs. Base Pointer Relative
Passing Parameters: best practices?
POC Version 2  BDD's topic there has a lot on stacks, relating to OSs.
Bruce Clark explains how the faster-running STC Forth avoids the expected memory penalties.  He gives 9 reasons, starting in the middle of his long post in the middle of the page.  STC of course eliminates the need for NEXT, nest, and unnest, thus improving speed.

On 6502.org:
Register Preservation Using The Stack (and a BRK handler), by Bruce Clark
[Small] Mini Multitasking Kernel for 6502 Systems, by Joachim Deboy
INVESTIGATING 65C816 INTERRUPTS by BDD (has a lot on the application programming interface or API near the end)
Context-Switching and Thread-Synchronization with a 6502, by André Fachat
65816 indirect threaded NEXT  Bruce Clark's topic on using S (the stack pointer register) as Forth's IP, so the program itself basically goes on the stack!  NEXT takes only 11 clocks.
65816 direct threaded NEXT  As above, but for DTC, and NEXT is even faster.  Again, the program itself goes on the stack.

On the 6502.org wiki:
Software 65816 Parameters On Stack
Software - 65816 - Relocatable code using BRL and PER
Software - Where-Am-I routines

Other:
BDD's 65816 follow-up on my article on 6502 interrupts.  He included a lot of information at the end regarding stack frames and the stack implications of multitasking.
This has some discussion on 6502 multitasking, with a lot of links.
operating-system wiki (OSDev.org)
Taygeta C64 Forths
EhBASIC, also here
Create your own Version of Microsoft BASIC for 6502
Microsoft BASIC for 6502 Original Source Code [1978]
description of RPL (Reverse-Polish Lisp)

My own:
6502 interrupts
servicing interrupts in high-level Forth with zero overhead
65c02 assembly structure macros
simple methods for multitasking without a multitasking OS, for systems that lack the resources for a multitasking OS, or where hard realtime requirements would rule one out anyway


And of course I can't pass up the opportunity to recommend the excellent programming manual available for free download, "Programming the 65816 including the 6502, 65C02, and 65802" by David Eyes and Ron Liechty.  This is a .pdf file of a rather large book that is well laid out and is much better than the description there lets on.  Note: There were many problems with the earlier .pdf version that were not in the original paper manual; but in late March 2015, WDC scanned and OCR'ed the paper manual and posted the new, repaired .pdf.




18. stack potpourri <--Previous   |   (Next--> Appendix A: data-stack ops for 6502)

last updated Feb 21, 2024