Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル

製品コード
SW006021-1
ページ / 518
MPLAB
®
 XC8 C Compiler User’s Guide
DS52053B-page 204
 2012 Microchip Technology Inc.
5.12.3.1
EQUIVALENT ASSEMBLY SYMBOLS
Most C symbols map to an corresponding assembly equivalent.
This mapping is such that an “ordinary” symbol defined in the assembly domain cannot 
interfere with an “ordinary” symbol in the C domain. So for example, if the symbol main 
is defined in the assembly domain, it is quite distinct to the main symbol used in C code 
and they refer to different locations.
The name of a C function maps to an assembly label that will have the same name, but 
with an underscore prepended. So the function main() will define an assembly label 
_main
.
Baseline PIC devices may use alternate assembly domain symbols for functions. The 
destinations of call instructions on these devices are limited to the first half of a program 
memory page. The compiler, thus, encodes functions in two parts, as illustrated in the 
following example of a C function, add(), compiled for a baseline device.
entry__add:
    LJMP    _add
The label entry__add is the function’s entry point and will always be located in a spe-
cial psect linked in the first half of a program memory page. The code associated with 
this label is simply a long jump (see Section 6.4.1.4 “Long Jumps and Calls”) to the 
actual function body located elsewhere and identified by the label _add.
If you plan to call routines from assembly code, you must be aware of this limitation in 
the device and the way the compiler works around it for C functions. Hand-written 
assembly code should always call the entry__funcName label rather than the usual 
assembly-equivalent function label.
If a C function is qualified static, and there is more than one static function in the 
program with exactly the same name, the name of the first function will map to the usual 
assembly symbol and the subsequent functions will map to a special symbol with the 
form: fileName@functionName, where fileName is the name of the file that 
contains the function, and functionName is the name of the function.
For example, a program contains the definition for two static functions, both called 
add
. One lives in the file main.c and the other in lcd.c. The first function will 
generate an assembly label _add. The second will generate the label lcd@add.
The name of a non-auto C variable also maps to an assembler label that will have the 
same name, but with an underscore prepended. So the variable result will define an 
assembly label: _result.
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 def-
inition) 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.