![background image](http://html1.mh-extra.com/html/texas-instruments/msp50c6xx/msp50c6xx_user-manual_1097068353.webp)
Beware of Stack Corruption
5-57
Code Development Tools
5.8
Beware of Stack Corruption
MSP50C614/MSP50P614 stack (pointed by R7 register) can easily get
corrupted if care is not taken. Notice the following table read code:
SUBB R7, 4
MOV A0, *R7––
ADD A0, address
MOV A0, *A0
ADD A0, *R7––
MOV A0, *A0
RET
This code will work perfectly well if no interrupts happen before SUBB and
MOV instruction. If interrupts do happen between SUBB and MOV
instructions, the parameter in the stack is corrupted by the return address
pushed by the hardware. This problem may not be easily observed in the
system level. But once it happens, it is very difficult to debug. Use the following
method to modify stack pointer instead:
MOV A0, *R7 + –2 * 2
ADD A0, address
MOV A0, *A0
ADD A0, *R7 + –2 * 1
MOV A0, *A0
RET
This method will not have the stack corruption problem since the MOV instruc-
tion performs the entire operation either before or after an interrupt.
Summary of Contents for MSP50C6xx
Page 6: ...vi...
Page 14: ...xiv...
Page 24: ...1 10...
Page 296: ...Instruction Set Summay 4 210 Assembly Language Instructions...
Page 366: ...6 12...