|
|||||||||||
|
Technical Support Support Resources
Product Information |
C51: Checking for Stack Underflow at RuntimeInformation in this article applies to:
QUESTIONI want to test the stack pointer (SP) in the main loop of my program to be sure that it has not underflowed. To do this, I need to get the address that SP is initialized to by the startup code. How can I do this? ANSWERFirst, you must modify the startup code to include a label for the bottom of the stack. Modify the startup code (STARTUP.A51) as shown below:
Note that the startup code loads the stack pointer as follows:
This means that in the main function, SP must be compared to the address of stackbot minus 1! In the file that contains the main C function, you must add the following definitions and declarations:
Note that stackbot is the bottom of the stack as declared in the STARTUP.A51 file. This is defined in the ?STACK segment in IDATA. The extern declaration is an array because you must access the address of stackbot - 1. Using an array, we can negatively index (using -1) and obtain this address as a constant. The following simple program shows how to use the STACK_START macro and the SP SFR to test the stack pointer.
SEE ALSO
Last Reviewed: Thursday, February 25, 2021 | ||||||||||
|
|||||||||||
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.