Re: [stella] Stack pointer. Some questions

Subject: Re: [stella] Stack pointer. Some questions
From: Christopher Tumber <christophertumber@xxxxxxxxxx>
Date: Sun, 09 May 2004 21:08:12 -0400
Happy Dude wrote:

>And the stack is 2 bytes in ram that points to code.

When the stack is being used to store JSR data this is PARTIALLY true, otherwise it is incorrect.

It's only partially true because such a stack may contain significantly more than 2 bytes.

For example:

   ldx #$ff
   jsr routine1
   jsr routine2
   jsr routine3

Results in a stack that is 6 bytes long and the stack pointer points at $f9

A stack can be any size - Though often limited by hardware. On the 2600 the stack has a physical limit of  256 bytes, with a practical limit of 128 bytes.

>So now that I am more knowledgable I will rephrase my question ;-)
>Is is possible to address the "stack" like other variables ?

- The "stack pointer" is a register, like A, X, Y, PC, Flags, etc.

The stack pointer can only be written to directly with the TXS command (There are other commands which will increment or decrement the stack pointer). The stack pointer can be used to store data, however it's generally too awkward and impractical to do so. In much the same way there are no math instruction related to the X and Y registers so you generally avoid using those registers to hold data that's going to need to be added or subtracted (or if you realise you're going to have to pass the data over to A first before you ADC or SBC). You can do anything you want with the registers, you can store data in the Flags register if you really want to. However, you're generally better off using the various registers as they're intended (unless you come up with something clever). Think of it as sawing with the grain instead of against it...

- A "stack" is a data structure. Some other examples of data structures are: Queue, Array, Linked list, Binary Tree, &etc.

By far (particularly on the 2600) the stack is most often used to store the return address for a JSR instruction. It's also used for temporary storage. There are also some tricks which involve use of the stack pointer (ie: Skipdraw) that don't really have anything to do with a stack.

On systems with a more liberal stack or stack pointer(s) (ie: with more RAM, or a stack pointer that is larger than 8-bit) a stack can have a variety of uses. Google up some computer science texts on stacks for more info (but largely irrelevant for the 2600).


Archives (includes files) at
Unsub & more at

Current Thread