Stack: Difference between revisions

Content added Content deleted
Line 7,121: Line 7,121:
On the Game Boy, the stack can also be manually adjusted by a signed 8-bit constant. A Zilog Z80 cannot do this in a single command. The code below only works on a Game Boy or any other hardware running on a Sharp LR35902 CPU:
On the Game Boy, the stack can also be manually adjusted by a signed 8-bit constant. A Zilog Z80 cannot do this in a single command. The code below only works on a Game Boy or any other hardware running on a Sharp LR35902 CPU:
<lang z80> ADD SP,&FE ;subtract two from the stack pointer. Remember that the stack grows "down" in memory.</lang>
<lang z80> ADD SP,&FE ;subtract two from the stack pointer. Remember that the stack grows "down" in memory.</lang>

It should be noted that although the "heap" and the "stack" are considered separate areas of memory by the programmer, in the eyes of the CPU there is no boundary between them. The CPU doesn't care if you push enough words onto the stack so that the stack pointer is now pointing to the heap, or even ROM space. Most of the time this isn't an issue, as long as your push/pop operations are properly balanced. It's just something to look out for.


=={{header|zkl}}==
=={{header|zkl}}==