Stack: Difference between revisions
(more push/pull instructions) |
(why pulling is slower) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
The '''Stack''' is a buffer which remembers the state of subroutines that are currently executing. | The '''Stack''' is a LIFO (last-in, first-out) buffer which remembers the state of subroutines that are currently executing. | ||
On the [[65c816]], the stack is always in [[bank]] zero.<sup>[3]</sup> It can be thousands of bytes deep.<sup>[1]</sup> | On the [[65c816]], the stack is always in [[bank]] zero.<sup>[3]</sup> It can be thousands of bytes deep.<sup>[1]</sup> | ||
Line 5: | Line 5: | ||
In [[emulation mode]] it wraps within page one.<sup>[2]</sup> | In [[emulation mode]] it wraps within page one.<sup>[2]</sup> | ||
The stack grows towards zero, but the most recently pushed byte is nontheless called the top of the stack. These instructions push things to the stack: | The stack grows towards zero, but the most recently pushed byte is nontheless called the top of the stack.<sup>[4]</sup> These instructions push things to the stack: | ||
* [[PEA]] | |||
* [[PEI]] | |||
* [[PER]] | |||
* [[PHA]] | * [[PHA]] | ||
* [[PHB]] | * [[PHB]] | ||
Line 16: | Line 19: | ||
* [[JSR]] | * [[JSR]] | ||
* [[JSL]] | * [[JSL]] | ||
* [[COP]] | |||
* [[BRK]] | |||
PL* instructions take one cycle more than their PH* counterparts. These instructions pull things from the stack: | PL* instructions take one cycle more than their PH* counterparts because they have to increment the stack pointer to point to the top element before it can be pulled, whereas push instructions pipeline the decrement of SP so that it overlaps the opcode fetch of the next instruction. These instructions pull things from the stack: | ||
* [[PLA]] | * [[PLA]] | ||
Line 29: | Line 34: | ||
* [[RTI]] | * [[RTI]] | ||
Note the lack of [[PLK]]. PHS and PLS similarly do not exist. | Note the lack of [[PLK]]. PHS and PLS similarly do not exist, nor do any instructions performing the inverse of PEA, PEI, or PER. | ||
=== See Also === | === See Also === | ||
Line 38: | Line 43: | ||
# Clark, Bruce. http://www.6502.org/tutorials/65c816opcodes.html#5.1.1 | # Clark, Bruce. http://www.6502.org/tutorials/65c816opcodes.html#5.1.1 | ||
# section 2.11 of 65c816 datasheet: https://www.westerndesigncenter.com/wdc/documentation/w65c816s.pdf | # section 2.11 of 65c816 datasheet: https://www.westerndesigncenter.com/wdc/documentation/w65c816s.pdf | ||
# [[Eyes & Lichty]], [https://archive.org/details/0893037893ProgrammingThe65816/page/33 page 33] | |||
[[Category:ASM]] | [[Category:ASM]] | ||
[[Category:Inherited from 6502]] | [[Category:Inherited from 6502]] | ||
[[Category:Buffers]] | [[Category:Buffers]] |
Latest revision as of 22:38, 12 November 2024
The Stack is a LIFO (last-in, first-out) buffer which remembers the state of subroutines that are currently executing.
On the 65c816, the stack is always in bank zero.[3] It can be thousands of bytes deep.[1]
In emulation mode it wraps within page one.[2]
The stack grows towards zero, but the most recently pushed byte is nontheless called the top of the stack.[4] These instructions push things to the stack:
PL* instructions take one cycle more than their PH* counterparts because they have to increment the stack pointer to point to the top element before it can be pulled, whereas push instructions pipeline the decrement of SP so that it overlaps the opcode fetch of the next instruction. These instructions pull things from the stack:
Note the lack of PLK. PHS and PLS similarly do not exist, nor do any instructions performing the inverse of PEA, PEI, or PER.
See Also
References
- Wilson, Garth. https://wilsonminesco.com/816myths
- Clark, Bruce. http://www.6502.org/tutorials/65c816opcodes.html#5.1.1
- section 2.11 of 65c816 datasheet: https://www.westerndesigncenter.com/wdc/documentation/w65c816s.pdf
- Eyes & Lichty, page 33