jrok, on Tue Aug 23, 2011 5:52 PM, said:
FYI, this doesn't seem to work quite as I expected (and maybe I'm just not thinking about it the right way). The stackpointer seems to work fine, but I thought "pull a-c" was intended to pull the range of a,b, and c starting at stack 197. If that's the case, shouldn't the following altered version display "040208"?
Yes, it should, but there appears to be a bug in the "pull #-#" code. I'll submit it to the bug thread shortly.
In the meantime, you can substitute "push a b c" and "pull c b a" instead, and it will work as expected.
jrok, on Tue Aug 23, 2011 5:52 PM, said:
EDIT: Actually, I'm a bit confused about how defining a range works with stack access. The only way I was able to get the stack to work in my RPG program was by reading the stack value directly after the location I wrote it to (for instance, I would push to stack 100, but pull from stack 99.)
You were doing it right for a single value. 2 things to keep in mind: (1) the stack grows toward 0. (2) the stack pointer always points to the topmost element in the stack.
So when you push a single value onto the stack at position 100, the new element goes on top of the element 100, at position 99. When you want to pull it, it needs to be from position 99. (after the pulling, the stack pointer will point to the next lower slot, at 100.)
If the stack pointer was at 100 and you push 3 values on the stack, when the operation is complete the stack pointer is 3 elements closer to 0, at 97. When you pull 3 elements from 97, they are "removed" and the stack pointer winds up pointing to the 100th element.
Clear, or no?