Keil™, An ARM® Company

Technical Support

C51: STACK POINTER INITIALIZATION IN STARTUP CODE


Information in this article applies to:

  • C51 Version 5.50
  • C51 Version 6.00 Beta
  • C51 Version 6.00

SYMPTOMS

The stack pointer is initialized at the end of the C startup code in STARTUP.A51. Why is this necessary?

CAUSE

The last few lines of the startup code appear as follows:

IF PBPSTACK <> 0
EXTRN DATA (?C_PBP)
                MOV     ?C_PBP,#LOW PBPSTACKTOP
ENDIF

                MOV     SP,#?STACK-1
                LJMP    ?C_START

After reset, the stack pointer is initialized to 07h. The stack will start growing up from address 8h.

The Keil C compiler uses internal DATA memory for your variables and also allows you to use register banks 1, 2, and 3. If the stack pointer were not adjusted, calls to functions and interrupts would overwrite your variables.

Therefore, the last thing the startup code does is to set the stack pointer to the end of all your internal DATA variables.

SEE ALSO

Last Reviewed: Friday, November 16, 2001


Did this article provide the answer you needed?
 
Yes
No
Not Sure