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.
Содержание MSP50C6xx
Страница 1: ...MSP50C6xx Mixed Signal Processor User s Guide Mixed Signal Products SPSU014A Printed on Recycled Paper...
Страница 6: ...vi...
Страница 14: ...xiv...
Страница 24: ...1 10...
Страница 296: ...Instruction Set Summay 4 210 Assembly Language Instructions...
Страница 332: ...Implementation Details 5 36 R7 Return Addr Return Addr Param 2 Param 2 Param 1 Param 1 R5 Stack data Function call...
Страница 366: ...6 12...