Page 1 of 1
cpu initial state
Posted: Sun Apr 19, 2009 10:28 pm
by tano6502
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
Posted: Sun Apr 19, 2009 10:46 pm
by GARTHWILSON
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.
Posted: Mon Apr 20, 2009 10:21 am
by tano6502
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
Posted: Mon Apr 20, 2009 5:46 pm
by HansO
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.
Posted: Mon Apr 20, 2009 7:24 pm
by GARTHWILSON
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.