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.9 shows an
example of damage caused when the stack pointer contains an odd address.
H'FECC
H'FECD
PCH
PCL
R1L
PCL
SP
SP
H'FECF
SP
BSR instruction
MOV.B R1L, @–R7
PC is improperly stored
beyond top of stack
PCH is lost
H'FECF set in SP
PCH: Upper byte of program counter
PCL: Lower byte of program counter
R1L: General register
SP: Stack pointer
Figure 4.9 Example of Damage Caused by Setting an Odd Address in R7
82