Stack Requirements

Building your first 6502-based project? We'll help you get started here.
Post Reply
User avatar
James_Parsons
Posts: 67
Joined: 10 Jul 2013

Stack Requirements

Post by James_Parsons »

http://www.devili.iki.fi/Computers/Comm ... e_274.html

what does it mean
Stack Requirements: 13
JMP $FFD2
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Stack Requirements

Post by BigDumbDinosaur »

James_Parsons wrote:
http://www.devili.iki.fi/Computers/Commodore/C64/Programmers_Reference/Chapter_5/page_274.html

what does it mean
Stack Requirements: 13
It means that the maximum stack space consumption during the subroutine call (ACPTR) is 13 bytes. An additional two stack bytes are used for the return address back to the calling program, which Commodore did not count as part of the kernel call's stack usage. ACPTR itself makes various internal subroutine calls to handshake the serial bus, which is where some of that stack space gets used.

Although the 6502's stack is tiny by current standards it can handle quite a few nested subroutines. Assuming the worst case, in which each subroutine pushes all registers for later restoration, 42 subroutines can theoretically be nested. I say "theoretically" because interrupts will also claim stack space. Plus when BASIC is running, the stack gets used for FOR-NEXT loops, as well as handling GOSUB-RETURN pairs. You can get an OUT OF MEMORY error in BASIC if too many GOSUBs or FOR-NEXT loops are nested. The choice of error for this situation is unfortunate, because there's plenty of memory when it happens. What is really happening is that the stack pointer has been driven too close to $00, leaving insufficient stack space for another GOSUB or FOR-NEXT.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: Stack Requirements

Post by GARTHWILSON »

From this page, it appears to be how many bytes' space it takes in the hardware stack (which is in page 1), not including the return address that gets put on it by your JSR that calls the routine. 13 bytes on that one is extraordinarily heavy stack usage. I looked at a lof of the following pages, and the other routines all took less, mostly zero to two.

It looks like you found a really good website there!
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: Stack Requirements

Post by barrym95838 »

GARTHWILSON wrote:
... It looks like you found a really good website there!
That guide is a classic ... I still have the paper-and-ink version (well worn from extensive use in 1984) on my bedroom bookshelf.

Mike
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Stack Requirements

Post by BigDumbDinosaur »

barrym95838 wrote:
GARTHWILSON wrote:
... It looks like you found a really good website there!
That guide is a classic ... I still have the paper-and-ink version (well worn from extensive use in 1984) on my bedroom bookshelf.

Mike
At one time I had it memorized. Time and some failed synapses have forced me to start reading again. :lol:
x86?  We ain't got no x86.  We don't NEED no stinking x86!
Post Reply