6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 7:57 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: cpu initial state
PostPosted: Sun Apr 19, 2009 10:28 pm 
Offline

Joined: Sun Apr 19, 2009 10:20 pm
Posts: 4
Hello,
what are exactly the state of the cpu registers and flags at startup
(or after a reset)? Datasheets and many docs on the net seems
not to answer this (perhaps obvious) question.
Thanks,
tano


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Apr 19, 2009 10:46 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
The interrupt-disable flag is set, the decimal flag is cleared, and the program counter is loaded with the value at FFFC-FFFD. Nothing else is guaranteed. In fact, on the NMOS 6502, even the decimal flag is not guaranteed after reset or interrupt. That fact that it is guaranteed on the CMOS ones is one of the many improvements that came with CMOS.

The 65816 appropriately has a few more guarantees. The data and program bank registers are zeroed, the high byte of the stack pointer is set to 01, the high bytes of the X and Y registers are zeroed, the 6502 emulation bit is set, and the direct-page register is zeroed.

Welcome to the forum. We've had quite a few legitimate new members join in the last several weeks.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Apr 20, 2009 10:21 am 
Offline

Joined: Sun Apr 19, 2009 10:20 pm
Posts: 4
Thanks! I forget to specify that I intend the NMOS version.
Looking in emulators source code I noted that reset code
seems also to clear all registers (a, x and y), and set the Zero
flag. Naturally the stack pointer should be set to 0x01ff.
But I think these are additions in respect to the natural behavior.
Bye,
tano


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Apr 20, 2009 5:46 pm 
Offline
User avatar

Joined: Fri Oct 31, 2003 10:00 pm
Posts: 200
GARTHWILSON wrote:
In fact, on the NMOS 6502, even the decimal flag is not guaranteed after reset or interrupt.


Indeed that seems to be random. The KIM-1 monitor ROM does not clear the decimal flag after reset. A major flaw and number 1 problem for new KIM-1 users in the old days. Second one was not connecting the +12V that was required for the cassette interface.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Apr 20, 2009 7:24 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
Quote:
Indeed that seems to be random. The KIM-1 monitor ROM does not clear the decimal flag after reset. A major flaw and number 1 problem for new KIM-1 users in the old days.

In the microprocessor class in 1982 on AIM-65's, we were taught to just initialize the decimal flag at the beginning of anything we did, just as we would not assume the accumulator or X or Y somehow automatically held the exact value we would happen to want first. It was no problem, but later with the 65c02 it was nice to be able to save a byte, and more importantly in ISRs, a couple of clocks, by being able to leave out the CLD.


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 57 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: