Stack register 9 bits?

Basic and Machine Language

Moderator: Moderators

Post Reply
Kakemoms
Vic 20 Nerd
Posts: 740
Joined: Sun Feb 15, 2015 8:45 am

Stack register 9 bits?

Post by Kakemoms »

This book points out the stack register as being 9 bits: http://www.1000bit.it/support/manuali/c ... e_code.pdf

It this true or is it a typo? Is there a way to extend the stack operation to being 512 bytes?
groepaz
Vic 20 Scientist
Posts: 1180
Joined: Wed Aug 25, 2010 5:30 pm

Re: Stack register 9 bits?

Post by groepaz »

typo ;)
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Stack register 9 bits?

Post by Mike »

I frankly don't know what could be misunderstood in the diagram on page 15. It shows the stack pointer as 9-bit value, with its bit 8 (value: 256) fixed at 1. It evidently follows, that the stack is located in addresses 256..511.

One could extend the representation with the higher bits 9..15 fixed at 0, and it would still be correct.
User avatar
srowe
Vic 20 Scientist
Posts: 1325
Joined: Mon Jun 16, 2014 3:19 pm

Re: Stack register 9 bits?

Post by srowe »

I've seen other books describe the stack pointer as a 16-bit register with a hard-wired page of one.

However you choose to represent it you can't move the stack from page 1. Shame as the push/pull instructions would be quite useful if they could access the full address space.
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Stack register 9 bits?

Post by Mike »

srowe wrote:[...] the push/pull instructions would be quite useful if they could access the full address space.
That begs the question why stop here, and not extend accumulator and index-registers to 16-bit as well.

In that case you'd end up with the 65C816 or 6809. :mrgreen:

For most applications on the 65xx, a 256 byte stack for sub-routine calls and small chunks of saved registers is probably sufficient. If a program has higher demands on stack size, it can always construct one by itself using a dedicated 16-bit pointer in the zeropage. That's what Commodore did, for example, with the 512 byte "run-time" stack on the later 8-bit BASICs, which separated FOR and DO loops, and GOSUBs from the machine-level sub-routine calls and register saves. It also helped with the handling of run-time errors, so BASIC flow-control constructions could be held alive during TRAP calls.
Kakemoms
Vic 20 Nerd
Posts: 740
Joined: Sun Feb 15, 2015 8:45 am

Re: Stack register 9 bits?

Post by Kakemoms »

Mike wrote:I frankly don't know what could be misunderstood in the diagram on page 15. It shows the stack pointer as 9-bit value, with its bit 8 (value: 256) fixed at 1. It evidently follows, that the stack is located in addresses 256..511.

One could extend the representation with the higher bits 9..15 fixed at 0, and it would still be correct.
I understand that its hardwired in the Vic-20, but is it really 9 bits inside the 6502 or 8-bits. In the latter case would it be possible to hack its location by rewiring inside the machine? Since CBM didn't do it I guess the answer is obvious..
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Stack register 9 bits?

Post by Mike »

... when the 6502 accesses the stack during interrupt processing or BRK (push PC, push status register), with RTI, PHx, PLx, JSR, RTS, it always puts $01 as high byte on the address bus and nothing can be done to persuade it to do something else.

You could put external hardware on the address bus to snoop for addresses in the $01xx range and then exchange the high byte with another value. That's what Commodore actually provided with the zero-page and stack translation registers in the MMU of the C128. However, there was no provision to check that really only a zero-page or stack access had taken place, and so the translation would also happen with $00xx or $01xx as effective addresses of all other 'generic' accesses.
Post Reply