Microchip Technology SW006021-2 Manual De Usuario
MPLAB
®
XC8 C Compiler User’s Guide
DS52053B-page 166
2012 Microchip Technology Inc.
5.5.2.1
NON-AUTO VARIABLE ALLOCATION
Non-auto variables (those with permanent storage duration) are located by the com-
piler into any of the available data banks. This is done in a two-stage process: placing
each variable into an appropriate psect and later linking that psect into a predetermined
bank. See Section 5.15.1 “Program Sections” for an introductory guide to psects.
Thus, during compilation, the code generator can determine which bank will hold each
variable and encode the output accordingly, but it will not know the exact location within
that bank.
piler into any of the available data banks. This is done in a two-stage process: placing
each variable into an appropriate psect and later linking that psect into a predetermined
bank. See Section 5.15.1 “Program Sections” for an introductory guide to psects.
Thus, during compilation, the code generator can determine which bank will hold each
variable and encode the output accordingly, but it will not know the exact location within
that bank.
The compiler will attempt to locate all variables in one bank (i.e., place all variables in
the psect destined for this bank), but if this fills (i.e., if the compiler detects that the psect
has become too large for the free space in a bank), variables will be located in other
banks via different psects. Qualifiers are not required to have these variables placed in
banks other than bank 0 but can be used if you want to force a variable to a particular
bank. See Section “--RAM=default,+20000-2FFFF.” and
Section 4.8.16 “--ADDRQUAL: Set Compiler Response to Memory Qualifiers” for
more information on how to do this. If common memory is available on the target
device, this will also be considered for variables. This memory may be limited in size
and may be reserved for special use, so only a few variables may be allocated to it.
the psect destined for this bank), but if this fills (i.e., if the compiler detects that the psect
has become too large for the free space in a bank), variables will be located in other
banks via different psects. Qualifiers are not required to have these variables placed in
banks other than bank 0 but can be used if you want to force a variable to a particular
bank. See Section “--RAM=default,+20000-2FFFF.” and
Section 4.8.16 “--ADDRQUAL: Set Compiler Response to Memory Qualifiers” for
more information on how to do this. If common memory is available on the target
device, this will also be considered for variables. This memory may be limited in size
and may be reserved for special use, so only a few variables may be allocated to it.
The compiler considers three categories of non-auto variables, which all relate to the
value the variable should contain by the time the program begins. Each variable cate-
gory has a corresponding psect which is used to hold the output code which reserves
memory for each variable. The base name of each psect category is tabulated below.
A full list of all psect names are in Section 5.15.2 “Compiler-Generated Psects”.
value the variable should contain by the time the program begins. Each variable cate-
gory has a corresponding psect which is used to hold the output code which reserves
memory for each variable. The base name of each psect category is tabulated below.
A full list of all psect names are in Section 5.15.2 “Compiler-Generated Psects”.
nv
These psects are used to store variables qualified persistent, whose values
should not be altered by the runtime startup code. They are not cleared or
otherwise modified at startup.
otherwise modified at startup.
bss
These psects contain any uninitialized variables, which are not assigned a value
when they are defined, or variables which should be cleared by the runtime
startup code.
startup code.
data
These psects contain the RAM image of any initialized variables, which are as-
signed a non-zero initial value when they are defined and which must have
a value copied to them by the runtime startup code.
a value copied to them by the runtime startup code.
As described in Section 5.10 “Main, Runtime Startup and Reset”, the base name of
data space psects is always used in conjunction with a linker class name to indicate the
RAM bank in which the psect will be positioned. This section also lists other variants of
these psects and indicates where these psect must be linked. See also
Section 5.15.2 “Compiler-Generated Psects” for more information on how initial
values are assigned to the variables.
data space psects is always used in conjunction with a linker class name to indicate the
RAM bank in which the psect will be positioned. This section also lists other variants of
these psects and indicates where these psect must be linked. See also
Section 5.15.2 “Compiler-Generated Psects” for more information on how initial
values are assigned to the variables.
Note:
The terms “local” and “global” are commonly used to describe variables, but
are not ones defined by the language Standard. The term “local variable” is
often taken to mean a variable which has scope inside a function, and
“global variable” is one which has scope throughout the entire program.
However, the C language has three common scopes: block, file (i.e., inter-
nal linkage) and program (i.e., external linkage), so using only two terms to
describe these can be confusing. For example, a static variable defined
outside a function has scope only in that file, so it is not globally accessible,
but it can be accessed by more than one function inside that file, so it is not
local to any one function, either.
are not ones defined by the language Standard. The term “local variable” is
often taken to mean a variable which has scope inside a function, and
“global variable” is one which has scope throughout the entire program.
However, the C language has three common scopes: block, file (i.e., inter-
nal linkage) and program (i.e., external linkage), so using only two terms to
describe these can be confusing. For example, a static variable defined
outside a function has scope only in that file, so it is not globally accessible,
but it can be accessed by more than one function inside that file, so it is not
local to any one function, either.