Hardware manual

Rev. 3.0, 09/98, page 76 of 361
4.4 Note on Stack Handling
In word access, the least significant bit of the address is always assumed to be 0. The stack is
always accessed by word access. Care should be taken to keep an even value in the stack pointer
(general register R7). Use the PUSH and POP (or MOV.W Rn, @SP and MOV.W @SP+, Rn)
instructions to push and pop registers on the stack.
Setting the stack pointer to an odd value can cause programs to crash. Figure 4.8 shows an
example of damage caused when the stack pointer contains an odd address.
SP
Legend:
PCH
PCL
R1L
SP
: Upper byte of program counter
: Lower byte of program counter
: General register
: Stack pointer
H'FECC
H'FECD
H'FECF
R1L
PC
L
SP
PC
H
PC
L
SP
MOV.B R1L, @-R7BSR instruction
H'FECF set in SP PC is improperly stored
beyond top of stack
PCH is lost
Figure 4.8 Example of Damage Caused by Setting an Odd Address in R7
Although the CCR consists of only one byte, it is treated as word data when pushed on the stack.
In the hardware interrupt exception-handling sequence, two identical CCR bytes are pushed onto
the stack to make a complete word. When popped from the stack by an RTE instruction, the CCR
is loaded from the byte stored at the even address. The byte stored at the odd address is ignored.