104
N OTES ON USE
4.2 Notes on programming
4.2.1 Processor Status Register
(1) Initialization of Processor Status Register
Flags which affect program execution must be initialized after a reset. In particular, it is essential
to initialize the T and D flags because they have an important effect on calculations.
●
Reason
After a reset, the contents of processor status register (PS) are undefined except for the I flag
which is “1.”
Fig. 4.2.1 Initialization of flags in Processor Status Register
(2) How to reference Processor Status Register
To reference the contents of the processor status register (PS), execute the PHP instruction
once then read the contents of (S + 1). If necessary, execute the PLP instruction to
return the PS to its original status.
A NOP instruction should be executed after every PLP instruction.
Reset
Flags initializing
Main program
Fig. 4.2.2 PLP instruction execution sequence
PLP instruction
NOP instruction
Fig. 4.2.3 Stack memory contents after PHP
instruction execution
(S)
(S) + 1
Saved PS