Download MPLAB XC8 C Compiler User's Guide

Transcript
C Language Features
If the C variable is qualified static, there, again, is a chance that there could be more
than one variable in the program with exactly the same C name. The same rules apply
to non-local static variables as to static functions. The name of the first variable
will map to a symbol prepended with an underscore; the subsequent symbols will have
the form: fileName@variableName, where fileName is the name of the file that
contains the variable, and variableName is the name of the variable.
For example a program contains the definition for two static variables, both called
result. One lives in the file main.c and the other in lcd.c. The first function will
generate an assembly label _result. The second will generate the label
lcd@result.
If there is more than one local static variable (i.e., it is defined inside a function definition) then all the variables will have an assembly name of the form:
functionName@variableName. So, if there is a static variable called output in
the function read, and another static variable with the same name defined in the
function update, then in assembly the symbols can be accessed using the symbols
read@output and update@output, respectively.
If there is more than one static function with the same name, and they contain definitions for static variables of the same name, then the assembly symbol used for
these variables will be of the form: fileName@functionName@variableName.
Having two static variables or functions with the same name is legal, but not
recommended as is easy to write code that accesses the wrong variable or calls the
wrong function.
Functions that use the reentrant model do not define any symbols that allow you to
access auto and parameter variables. You should not attempt to access these in
assembly code. Special symbols for auto and parameter variables are defined,
however, by functions that use the non-reentrant model. These symbols are described
in the following paragraphs.
To allow easy access to parameter and auto variables on the compiled stack, special
equates are defined which map a unique symbol to each variable. The symbol has the
form: functionName@variableName. Thus, if the function main defines an auto
variable called foobar, the symbol main@foobar can be used in assembly code to
access this C variable.
Function parameters use the same symbol mapping as auto variables. If a function
called read has a parameter called channel, then the assembly symbol for that
parameter is read@channel.
Function return values have no C identifier associated with them. The return value for
a function shares the same memory as that function’s parameter variables, if they are
present. The assembly symbol used for return values has the form ?_funcName,
where funcName is the name of the function returning the value. Thus, if a function,
getPort returns a value, it will be located the address held by the assembly symbol
?_getPort. If this return value is more than one byte in size, then an offset is added
to the symbol to access each byte, e.g., ?_getPort+1.
If the compiler creates temporary variables to hold intermediate results, these will
behave like auto variables. As there is no corresponding C variable, the assembly
symbol is based on the symbol that represents the auto block for the function plus an
offset. That symbol is ??_funcName, where funcName is the function in which the
symbol is being used. So for example, if the function main uses temporary variables,
they will be accessed as an offset from the symbol ??_main.
 2012-2013 Microchip Technology Inc.
DS50002053D-page 215