Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual
Product codes
SW006021-1
C Language Features
2012 Microchip Technology Inc.
DS52053B-page 207
5.12.3.4
UNDEFINED SYMBOLS
If a variable needs to be accessible from both assembly and C source code, it can be
defined in assembly code, if required, but it is easier to do so in C source code.
defined in assembly code, if required, but it is easier to do so in C source code.
A problem could occur if there is a variable defined in C source, but is only ever refer-
enced in the assembly code. In this case, the code generator would remove the vari-
able believing it is unused. The linker would be unable to resolve the symbol referenced
by the assembly code and an error will result.
enced in the assembly code. In this case, the code generator would remove the vari-
able believing it is unused. The linker would be unable to resolve the symbol referenced
by the assembly code and an error will result.
To work around this issue, MPLAB XC8 also searches assembly-derived object files for
symbols which are undefined. see Section 4.3.4 “Compilation of Assembly
Source”. These will be symbols that are used, but not defined, in assembly code. The
code generator is informed of these symbols, and if they are encountered in the C code,
the variable is automatically marked as being volatile. This action has the same effect
as qualifying the variable volatile in the source code, see Section 5.4.7.2 “Volatile
Type Qualifier”.
symbols which are undefined. see Section 4.3.4 “Compilation of Assembly
Source”. These will be symbols that are used, but not defined, in assembly code. The
code generator is informed of these symbols, and if they are encountered in the C code,
the variable is automatically marked as being volatile. This action has the same effect
as qualifying the variable volatile in the source code, see Section 5.4.7.2 “Volatile
Type Qualifier”.
Variables qualified as volatile will never be removed by the code generator, even if
they appear to be unused throughout the program.
they appear to be unused throughout the program.
For example, if a C program defines a global variable as follows:
int input;
but this variable is only ever used in assembly code. The assembly module(s) can
simply declare this symbol using the GLOBAL assembler directive, and then use it. The
following PIC18 example illustrates the assembly code accessing this variable.
simply declare this symbol using the GLOBAL assembler directive, and then use it. The
following PIC18 example illustrates the assembly code accessing this variable.
GLOBAL _input, _raster
PSECT text,local,class=CODE,reloc=2
_raster:
MOVF
_input,w
The compiler knows of the mapping between the C symbol input, and the corre-
sponding assembly symbol _input (see Section 5.12.3 “Interaction Between
Assembly and C Code”). In this instance the C variable input will not be removed
and be treated as if it was qualified volatile.
sponding assembly symbol _input (see Section 5.12.3 “Interaction Between
Assembly and C Code”). In this instance the C variable input will not be removed
and be treated as if it was qualified volatile.