ARM Stack Frame Layout

The following illustration shows the stack frame layout.

The following list gives more information about the stack frame layout.

  • The Register Save Area holds the preserved values of any permanent registers used by the function. It also contains the function return address.

  • The Locals and Temporaries area represents the stack space allocated for local variables and compiler-generated temporaries.

  • The first four words at the top of the stack may contain the values passed in R0-R3. Any of these values could be missing. The values should be stored in the R0-R3 if registers cannot hold the arguments for the entire function, or if the addresses for the arguments are already in use.

  • If a routine needs storage space for the first four words of arguments, it creates and initializes the storage at the very top of the called function stack. The following list shows reasons for which a routine can allocate space:

    • An argument word address is taken
    • An argument word has a value altered by the called function
    • An argument register must be spilled.

    If a register keeps an argument for the argument live range, the argument has no associated storage in the stack frame.

  • If a routine has alloca() locals, the ARM Specification requires a separate frame pointer register to access incoming arguments and locals. R11 is the assigned frame pointer for ARM, and R7 is the assigned frame pointer for THUMB. A leaf routine may use any free integer register as the frame pointer. A non-leaf routine must use a permanent register. The routine must not modify the frame pointer register between the prolog and epilog.

  • In a routine that uses alloca(), everything in the frame at a lower address than the alloca() area is referenced relative to R13 and never contains a defined value at the time of an alloca() call. Thus, the alloca() operation never has to copy this part of the stack frame, and no data relocation problems arise. Everything in the frame at an address higher than the alloca() area is referenced relative to the frame pointer, R11 for ARM or R7 for THUMB.

  • To more efficiently access data in large stack frames, a routine may establish another frame pointer. A frame pointer helps mitigate problems with the limited size of the bit-field that specifies register-displacement-addressing offset. The frame pointer typically points to a fixed frame offset in the RSA or Local and Temporaries areas of the stack frame, but may point to other offsets within the frame.

  • A routine need not set up a stack frame for itself unless it needs to save permanent registers, or to allocate space for locals or outgoing argument areas that are bigger than four words.

  • The stack pointer and frame pointer addresses align on 4-byte boundaries.

See Also

ARM Calling Sequence Specification | What's New for the ARM Compiler | ARM Registers | ARM Parameter Passing | ARM Return Values | ARM Prolog and Epilog | ARM pdata Structures | ARM Assembler Macros

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.