# Software stack The software stack is divided into frames. In general, there is one frame for each active function. The exception to this rule is described later. First, we describe the layout of each frame. The current stack frame is marked by the frame pointer register (R30) and the stack pointer register (R29). The stack grows toward smaller addresses in memory. Stack frames are always aligned on 8-byte boundaries. This enables the alignment of data within each frame. ## Stack sections Each stack frame contains the following sections, in decreasing memory order: 1. Saved R31, saved R30 The allocframe instruction is used to save the values of R31 (the function return address) and R30 (frame pointer) during the function prologue. 2. Locals/spill area This optional area contains enough space for: - Any local variables that require stack space - Any register spills (including callee saved registers) that are required > > > The size of this area is determined at compile time on a per function > basis. To minimize the amount of padding between variables, QTI > recommends (but does not require) that the data in this section is > ordered. 3. Alloca area This optional area contains space allocated by alloca. The size of this area is determined at run time based on the alloca calls that are executed. Initially, this size is zero. 4. Outgoing memory arguments This optional area is used when the function calls one or more functions whose arguments cannot all be passed in registers. The size of this area is determined at compile time on a per function basis. Within the function, the compiler examines all function calls and determines the maximum space required for any call. This scheme makes function calls fast and simple at the expense of some wasted space. Each section must be aligned to an 8-byte boundary. If necessary, add padding in the high memory address of each section. Within each section, the normal data alignment rules apply ([Memory alignment](https://docs.qualcomm.com/doc/80-N2040-23/topic/data-types.html#memory-alignment)). **Stack in memory** stack Sheet.4 Sheet.7 R29 R29 Sheet.11 Sheet.12 R30 R30 Sheet.14 Sheet.15 Sheet.16 Sheet.19 Sheet.20 Sheet.21 Lower Address Lower Address Sheet.22 Sheet.23 Higher Address Higher Address Sheet.24 Sheet.25 Sheet.29 Sheet.30 Sheet.35 Sheet.38 Sheet.39 Sheet.41 Sheet.42 Sheet.46 Sheet.47 Sheet.49 Saved R31 Saved R31 Sheet.50 Sheet.51 Sheet.53 Saved R30 Saved R30 Sheet.54 Sheet.55 Sheet.58 Sheet.59 Sheet.61 Sheet.62 Sheet.66 Sheet.67 Sheet.68 Previous Frame Previous Frame Sheet.70 Sheet.71 Sheet.72 Current Frame Current Frame Sheet.73 Sheet.17 Unallocated Stack Unallocated Stack Sheet.36 Locals/Spill Area Locals/Spill Area Sheet.40 Alloca Area Alloca Area Sheet.43 Outgoing Memory Arguments Area Outgoing Memory Arguments Area Sheet.56 Locals/Spill Area Locals/Spill Area Sheet.60 Alloca Area Alloca Area Sheet.63 Outgoing Memory Arguments Area Outgoing Memory Arguments Area Sheet.2 Saved R31 Saved R31 Sheet.3 Saved R30 Saved R30 Sheet.74 Sheet.5 Note For performance reasons, certain functions are allowed to avoid the overhead of allocating and deallocating a frame. A function that does not make any calls is called a *leaf function*. A leaf function that does not require any stack space (i.e., the size of each optional area is zero) cannot allocate a frame. Last Published: Oct 06, 2026 [Previous Topic Heap allocation](https://docs.qualcomm.com/bundle/publicresource/80-N2040-23/topics/data-types.md) [Next Topic Parameter passing](https://docs.qualcomm.com/bundle/publicresource/80-N2040-23/topics/parameter-passing.md)