Microchip Technology SW006023-2N Data Sheet
Memory Allocation and Access
2012 Microchip Technology Inc.
DS51686E-page 113
FIGURE 7-1:
STACK FRAME
The the standard qualifiers const and volatile may both be used with auto vari-
ables and these do not affect how they are positioned in memory. This implies that a
local const-qualified object is still an auto object and, as such, will be allocated mem-
ory on the stack in the data memory, not in the program memory like with non-auto
const
ables and these do not affect how they are positioned in memory. This implies that a
local const-qualified object is still an auto object and, as such, will be allocated mem-
ory on the stack in the data memory, not in the program memory like with non-auto
const
objects.
7.4.1
Local Variable Size Limits
There is no theoretical maximum size for auto variables.
7.5
VARIABLES IN PROGRAM MEMORY
The only variables that are placed into program memory are those that are not auto
and which have been qualified const. If the -mno-embedded-data option is used,
then even const objects are placed in RAM rather than the program memory. Any
auto
and which have been qualified const. If the -mno-embedded-data option is used,
then even const objects are placed in RAM rather than the program memory. Any
auto
variables qualified const are placed on the stack along with other auto vari-
ables.
Any const-qualified (auto or non-auto) variable will always be read-only and any
attempt to write to these in your source code will result in an error being issued by the
compiler.
attempt to write to these in your source code will result in an error being issued by the
compiler.
A const object is usually defined with initial values, as the program cannot write to
these objects at runtime. However this is not a requirement. An uninitialized const
object is allocated space in the bss section, along with other uninitialized RAM vari-
ables, but is still read-only.
these objects at runtime. However this is not a requirement. An uninitialized const
object is allocated space in the bss section, along with other uninitialized RAM vari-
ables, but is still read-only.
const char IOtype = ’A’; // initialized const object
const char buffer[10]; // I just reserve memory in RAM
Stack grows
toward
lower
addresses
toward
lower
addresses
FP
Caller
Space for more
arguments if
necessary
arguments if
necessary
Space for argument 4
Space for argument 3
Space for argument 2
Space for argument 1
Local variables and
temporary values
temporary values
Register save area
Space for arguments
used in function calls
used in function calls
Callee
SP