I'm reading about the 6502 processor's instruction set from the many links at 6502.org, and one tutorial states:

The stack pointer (S) points to a byte on Page 1, that is, to a byte whose address is from 0100 to 01FF, where the last two digits are supplied by S. When a byte is pushed on the stack, it is written at the address in S, and then S is decremented.

The S register is 1 byte, so it obviously holds a value from 00 to FF, but since it decrements upon pushes, when nothing has yet been pushed on, it must start at FF. Does the physical hardware (transistors) in the chip set all the bits in that register to '1' when the chip gets its first breath of power?

I just like to know the low-level details.

link|improve this question

80% accept rate
What's the over/under on somebody actually knowing this, I wonder...:) – Shinrai Oct 14 '11 at 17:40
feedback

1 Answer

http://forum.6502.org/viewtopic.php?t=468&sid=ccdf15a560f1520a347ba896ae89767f claim that it's not specified.

http://whats.all.this.brouhaha.com/2011/07/07/stack-usage-in-the-apple-1-monitor/ also claims that it's not specified and further that it doesn't matter if you don't care about the exact position of the stack within that page. Wherever it starts it will wrap round, so as long as you don't use more than 256 bytes of stack you're fine.

http://visual6502.org/JSSim/ which is a transistor-level simulation of actual hardware appears to boot up with SP set to FD; you could probably trace the actual registers there and determine if that's deliberate or just a coincidence.

(In that context "monitor" means a low level control program rather than a display)

link|improve this answer
re "it doesn't matter if you don't care about the exact position of the stack": if you use the stack to store locals or function arguments, you will care about the exact position of the stack. E.g. reading the second local from the stack to the accumulator (TSX / LDA $00FF,X) will fail if the stack pointer is at 0 because you will read from $00FF instead of $01FF. This can easily happen if the stack starts at too low an address. This issue only applies if you access the stack with absolute indexed addressing, though. – Snarfblam 3 hours ago
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.