Texas Instruments MSP50C614 Stereo System User Manual


 
Beware of Stack Corruption
5-67
Code Development Tools
5.11 Beware of Stack Corruption
MSP50C614/MSP50P614 stack (pointed by R7 register) can easily get cor-
rupted 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 instruc-
tions, 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.
5.12 Reported Bugs With Code Development Tool
The following are the reported bugs for code development tool version 2.14.
Breakpoint: Hardware breakpoint within two instruction cycles after the
IDLE instruction causes the program to hang. Avoid putting breakpoint af-
ter IDLE instruction within two instruction cycle.