6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 16, 2024 9:36 pm

All times are UTC




Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Thu Aug 23, 2012 1:29 pm 
Offline
User avatar

Joined: Mon Dec 08, 2008 6:32 pm
Posts: 143
Location: Brighton, England
BigDumbDinosaur wrote:
I don't know anyone who uses Pascal anymore.

I do! One day I may even get my Pascal compiler for the 65C02 working!

I can confirm that Pascal stores ALL local variables on the stack (although more recent implementations usually store large items, such as strings and objects, elsewhere and just store a pointer to them on the stack.) 6502 implementations of Pascal usually use a pair of zero page bytes as a stack pointer, allowing the stack to use all the available memory. the (ZP),Y addressing mode is usefull here as it allows one to read data at an offset from the stack pointer.

_________________
Shift to the left,
Shift to the right,
Mask in, Mask Out,
BYTE! BYTE! BYTE!


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 13, 2015 12:54 am 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
I have a related question which maybe fits this thread. It came up while coding my Crude Emulator for the 65816: When a RESET is triggered, p. 201 of Eyes and Lichty says that the MSB of the Stack Pointer is set to $01. It says nothing about the LSB. Do we know if it is preserved or is the state undefined afterwards?


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 13, 2015 1:07 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8491
Location: Midwestern USA
scotws wrote:
I have a related question which maybe fits this thread. It came up while coding my Crude Emulator for the 65816: When a RESET is triggered, p. 201 of Eyes and Lichty says that the MSB of the Stack Pointer is set to $01. It says nothing about the LSB. Do we know if it is preserved or is the state undefined afterwards?

At power-up, the LSB of SP is random. Otherwise, I don't know what its state might be. I could burn an EPROM for POC that writes SP to an otherwise unused location in RAM at reset and see what pops up.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 13, 2015 2:28 am 
Online
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8541
Location: Southern California
Klaus2m5 wrote:
If nothing else uses page 1 ($100-$1ff) it is not necessary to initialize the stackpointer. The stackpointer will simply wrap around if decremented below zero. So there is no reason for the hardware to initialize it.

However, it still is good practice to initialize it by software to $ff. This allows you to use the lower part of page 1 for other purposes than stack. Debugging of a runaway stack may also benefit from this (knowing where the SP should point at).

I don't know why I didn't think to address this the first time around (three years ago), although BDD alluded to it WRT the '816. When parameters are passed to a subroutine on the hardware stack, it is common for the subroutine to access them by doing for example,
Code:
        TSX
        LDA  105,X

to reach past the subroutine return address and past two more bytes, to the parameter byte just past that. It could easily be more, like 108,X. In that case, you can see that you would want the stack initialized to $FF; because if it were to ever wrap (like if you started with S=03 instead of $FF, this indexing could get you out of the stack area and into page 2. [Edit: This is mentioned in the note in the middle of chapter 5 of my 6502 stacks treatise which has 19 chapters plus appendices. There's more explanation 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?


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 13, 2015 3:39 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
scotws wrote:
When a RESET is triggered, p. 201 of Eyes and Lichty says that the MSB of the Stack Pointer is set to $01. It says nothing about the LSB. Do we know if it is preserved or is the state undefined afterwards?
The state of the LSB of S is undefined after power-up -- just garbage. But reset is a different matter -- is that really what you intended to ask? (Reset and power-up aren't the same. The chip can be reset repeatedly after it's powered up.)

Reset takes whatever is already in the LSB -- power-up garbage or otherwise -- and decrements it by three. That's because reset is a form of interrupt, and involves pushing via the stack pointer (although dummy cycles replace the writes if the interrupt is a reset). Table 5-7, row 22a of the '816 data sheet shows this.

[Edit:] Section 2.5 says, "When Reset is brought high, an interrupt sequence is initiated." Apparently the reset interrupt is edge-triggered (like NMI, just with opposite polarity). Multiple iterations of the reset interrupt sequence will not occur, contrary to some speculation I expressed earlier.

-- Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 13, 2015 9:51 am 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
Dr Jefyll wrote:
The state of the LSB of S is undefined after power-up -- just garbage. But reset is a different matter -- is that really what you intended to ask?


Right. I know it's garbage after power-up, but had never thought about RESET until I had to write a routine for it ... thanks for the explanation!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: