GB Programming: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
>ISSOtm (→Negative numbers: Changed ALL the ranges, the dashes could be mistaken for minus signs.) |
>ISSOtm m (→A stack? Can you eat that?: Changed the first three words. Pointless but more consistent with the title, I guess.) |
||
Line 632: | Line 632: | ||
==Stacks== |
==Stacks== |
||
===A stack? Can you eat that?=== |
===A stack? Can you eat that?=== |
||
No |
No you can't. It's a data structure that has the cool property of not being fixed-length. How does it work? Just like a stack of plates. Imagine you're washing some plates in the back of a restaurant. Next to you is a pile of plates you need to wash. Waiters come and place ("push") plates on top of the stack and when finished washing a plate, you take ("pop") the topmost one. This way of working is called LIFO (Last In First Out). |
||
In our case, we will do it by saving the top of the stack as a memory address. This value is called the ''stack pointer''. Here is an example, with the stack growing to the right : |
In our case, we will do it by saving the top of the stack as a memory address. This value is called the ''stack pointer''. Here is an example, with the stack growing to the right : |
||
Line 666: | Line 666: | ||
|$00||$03||$4F||$C0||$7C||$2A||??||??||??||??||??||??||??||??||??||?? |
|$00||$03||$4F||$C0||$7C||$2A||??||??||??||??||??||??||??||??||??||?? |
||
|} |
|} |
||
===Coding a stack=== |
===Coding a stack=== |