6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 8:19 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu Dec 20, 2012 3:05 pm 
Offline

Joined: Fri Sep 28, 2012 12:27 pm
Posts: 25
Location: Boulogne Billancourt, France
Hello,

I've looked at various documents from where I am but none appear to directly answer to this query:
In emulation mode, does an instruction LDA d,S wrap around page 1 for computing its effective address?
In other word, does the sequence
SEC
XCE
LDX #$FF
TXS
LDA 1,S
will load the content of address $100 (wraparound) or the content of address $200 (no wraparound)?
I understand that the answer is negative when in native mode (as the hardware stack can be anywhere in the first 64K of memory, and is not limited to a page size).

Thank you for any info on this.
Best regards,
Benoît


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 20, 2012 3:23 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
That's an interesting conundrum. The page talking about the address mode in the Programming Guide makes no mention. But to be fair it doesn't say anything about the wrap around behavior for the Push and Pull instructions either. We "know" this happens with the 6502, but I have not seen it documented. It's more folklore (heard from a friend who heard from a friend who saw it in the wild and told two people who told two people...).

Someone would have to test it and see, or I guess maybe you could write WDC and see what they say.


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 20, 2012 3:31 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
Here we go:

Page 278 of http://www.westerndesigncenter.com/wdc/ ... manual.pdf

Quote:
65802/65816: Stack Overruns Program or Data

No longer limited to a single page, the native-mode stack will grow downward as far as your program pushes bytes onto it. Large programs should either retrieve every byte pushed on or reset the stack periodically (using TCS or TXS). The potential danger is when a stack grows uncontrollably until it overwrites variables, your program, or the operating system.

In this connection it is important to be aware that, although the high byte of the stack register is consistently forced to one, new 65816 opcodes executed in the emulation mode will not wrap the stack if the low byte over- or underflowed in the middle of an instruction. For example, if the stack pointer is equal to $101, and a JSL is executed, the final byte of the three bytes pushed on the stack will be at $FF, not $1FF; but the stack pointer at the end of the instruction will point to $1FE. However, if JSR (a 6502 instruction) is executed in the emulation mode with the stack pointer equal to $100, the second of the two bytes pushed will be stored at $1FF.


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 20, 2012 5:05 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8506
Location: Midwestern USA
Benoit0123 wrote:
Hello,

I've looked at various documents from where I am but none appear to directly answer to this query:
In emulation mode, does an instruction LDA d,S wrap around page 1 for computing its effective address?
In other word, does the sequence
SEC
XCE
LDX #$FF
TXS
LDA 1,S
will load the content of address $100 (wraparound) or the content of address $200 (no wraparound)?
I understand that the answer is negative when in native mode (as the hardware stack can be anywhere in the first 64K of memory, and is not limited to a page size).

Thank you for any info on this.
Best regards,
Benoît

In your example, LDA 1,S will load from $000200.

Where wrap would get into the picture would be in the following native mode example:
Code:
         rep #%00100000        ;16 bit accumulator
         lda #$ffff
         tcs                   ;set stack pointer
         sep #%00100000        ;8 bit accumulator
         lda $01,s             ;load from stack

In the above sequence, the load would be from $000000, as stack references are always directed to bank $00. This is in contrast to ordinary loads, in which the effective data bank is autoincremented. For example:
Code:
         sep #%00100000        ;8 bit accumulator
         rep #%00010000        ;16 bit index
         lda #$00
         pha
         plb                   ;set data bank to $00
         ldx #$ffff
         lda $01,x

In the above example, the load will be from $010000, assuming the bank address is being implemented in the hardware.

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


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 20, 2012 6:25 pm 
Offline

Joined: Fri Sep 28, 2012 12:27 pm
Posts: 25
Location: Boulogne Billancourt, France
Thank you to you all...
So from now on I will presume that there will be no wraparound in this case..

Merry Christmas and happy New Year,
Best regards,
Benoît


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 15 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: