6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Mar 28, 2024 5:19 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Fri May 28, 2004 7:09 pm 
Offline

Joined: Fri May 21, 2004 5:23 pm
Posts: 17
Location: Burlington, ON
Hi,

After a RESET is performed what is the value of the following registers and the stack pointer?

Accumulator
IX
IY
Processor Status Flags
Stack Pointer

The reason I'm asking is that I have conflicting sources of information and I was hoping there would be an expert on here who could help me out.

Thanks in advance,

Andrew :?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri May 28, 2004 8:16 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8412
Location: Southern California
Coming out of RESET, the interrupt-disable bit I is set, and if you have a CMOS 6502 (65c02), the decimal flag D is clear. The other processor status bits are not specified to be one way or another, and the A, X, Y, and S (stack pointer) are not specified to have any particular value. SToP and WAIt instructions are cleared, and execution begins at the address pointed to by the reset vector at address FFFC-FFFD.

Your reset routine will typically have LDX #$FF, TXS so the stack pointer S starts at $1FF. The stack grows down (1FE, 1FD, 1FC, etc..). The high byte of the stack pointer is always 1 for the 6502/65c02. If you have an NMOS 6502, a CLD will also typically be one of the first things in your reset routine.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri May 28, 2004 8:39 pm 
Offline

Joined: Fri May 21, 2004 5:23 pm
Posts: 17
Location: Burlington, ON
GARTHWILSON wrote:
The other processor status bits are not specified to be one way or another, and the A, X, Y, and S (stack pointer) are not specified to have any particular value.


Hey Garth,

A document from Western Design Center shows the RESET pushing the Program Counter and Processor Status Flags onto the stack... do you know if that is correct? Does a RESET push these registers onto the stack?

Also, when you say that they are not specified, do you mean that they can be any value? Or, do you mean that there is no supporting documentation to say what they are?

Thanks for the help,

Andrew :)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri May 28, 2004 9:13 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8412
Location: Southern California
> shows the RESET pushing the Program Counter and Processor Status
> Flags onto the stack... do you know if that is correct? Does a RESET
> push these registers onto the stack?

RESET is an interrupt of sorts, and I do seem to remember seeing it push these things onto the stack when I've done single-cycling experiments. Maybe it could show you where the program counter was and what the status register were when you aborted a crashed condition by pressing the RESET button, but so far I've never had any reason to care.

> Also, when you say that they are not specified, do you mean that they
> can be any value? Or, do you mean that there is no supporting
> documentation to say what they are?

My answer would be B. Some (time-consuming) experiments could show if the non-specified flags and registers would just retain the values they had when the RESET line went true if in fact RESET was used to recover from a crash, but that might not be very useful information. If you're just powering up, I don't think you could count on any particular values being in those bits and registers. It might be pretty consistent with one particular processor but different with another one of the same kind from a different production lot. RAM is similar. People have tried to use the random power-up values in for a random-number generator, but many RAMs are surprisingly consistent in what they power up with.

If you're rather new to this stuff, I would recommend just making your RESET routine initialize things the way you want them, and don't worry about what might have been there before initialization. The point of the RESET routine is to set things up to begin operation, the bulk of that being I/O bit directions, timers and counters, initial variable values, etc.. You'll be changing the processor register values while doing this job anyway, so what was there earlier just doesn't matter in most cases.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri May 28, 2004 10:54 pm 
Offline
User avatar

Joined: Thu Mar 11, 2004 7:42 am
Posts: 362
GARTHWILSON wrote:
> shows the RESET pushing the Program Counter and Processor Status
> Flags onto the stack... do you know if that is correct? Does a RESET
> push these registers onto the stack?

RESET is an interrupt of sorts, and I do seem to remember seeing it push these things onto the stack when I've done single-cycling experiments.


It doesn't look like you can rely on the behavior, though. I ran a couple of quick experiments. With the following code, I pressed RESET once it got to the BNE loop.

Code:
      LDX #$7F  ; clears Z flag, so BNE will branch
      TXS
LABEL BNE LABEL


The LDX #$7F is just to move the stack pointer out far enough so that once the stack pointer is reset, the initialization routines won't clobber the effect RESET has on the stack. The reset handler I used was:

Code:
CLD
TSX
STX MEMORY
LDX #$FF
TXS
JMP RESET


On my 65C02, it appeared to push the PC and P register correctly at $17D to $17F. However, on my Synertek (NMOS) 6502, the stack pointer (stored in MEMORY) was $7C, but nothing got written to $017D to $017F. No matter what values I put there, they were never overwritten.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jun 01, 2004 10:57 am 
Offline

Joined: Tue Sep 03, 2002 12:58 pm
Posts: 288
[quote="andrewem"]
A document from Western Design Center shows the RESET pushing the Program Counter and Processor Status Flags onto the stack... do you know if that is correct? Does a RESET push these registers onto the stack?
[/quote]

Many years ago I had a logic analyser hooked up to my C64. The NMOS 6510 does a few cycles that look like it's pushing PC and P, but R/W is high so nothing gets written.


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

All times are UTC


Who is online

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