Hello, I was working on emulating 6502 processor, I came to know that 6502 has a 8bit SP which starts from 0x0100 to 0x01FF. So how does it store 0x01FF which is over 8 bits.<p>Thankyou!
There are only 256 different values for the stack pointer. That’s low enough to fit in a 8-bit register.<p>See it as a digital display with two hex digits and the value “0x01” painted in front of it:<p><pre><code> 0x0142
^^ two hex digits: the value in the register
^^^^ painted on the front plate of the display
</code></pre>
The cpu, similarly, hard-wires those 8 bits (seven zeros and a single one) in front of the register value when accessing the stack.
It does not store 01ff. It stores 00 to ff. The stack is always on page 1 (0x01..) and can not be moved elsewhere. The CPU hardware simply outputs 0x01 on the upper eight bits of the address bus while outputting the 8-bit stack pointer on the lower eight bits of the bus.