ARM Technical Support Knowledge Articles

STACK POINTER INITIALIZATION IN STARTUP CODE

Applies to: C51 C Compiler

Answer


Information in this article applies to:


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

Article last edited on: 2001-11-16 00:00:00

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential