Microchip Technology SW006021-2 Manual De Usuario
C Language Features
2012 Microchip Technology Inc.
DS52053B-page 205
If there is more than one static function with the same name, and they contain defi-
nitions for static variables of the same name, then the assembly symbol used for
these variables will be of the form: fileName@functionName@variableName.
nitions 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 recom-
mended as the wrong variable may be accessed or the wrong function called.
mended as the wrong variable may be accessed or the wrong function called.
To make accessing of parameter and auto variables easier, special equates are
defined which map a unique symbol to each variable. The symbol has the form:
functionName@variableName
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.
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.
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
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.
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.
5.12.3.2
ACCESSING REGISTERS FROM ASSEMBLY CODE
If writing separate assembly modules, SFR definitions will not automatically be acces-
sible. The assembly header file <xc.inc> can be used to gain access to these register
definitions. Do not use this file for assembly inline with C code as it will clash with def-
initions in <xc.h>.
sible. The assembly header file <xc.inc> can be used to gain access to these register
definitions. Do not use this file for assembly inline with C code as it will clash with def-
initions in <xc.h>.
Include the file using the assembler’s INCLUDE directive, (see
Section 6.4.10.4 “INCLUDE”) or use the C preprocessor’s #include directive. If you
are using the latter method, make sure you compile with the -P driver option to prepro-
cess assembly files, see Section 4.8.11 “-P: Preprocess Assembly Files”.
Section 6.4.10.4 “INCLUDE”) or use the C preprocessor’s #include directive. If you
are using the latter method, make sure you compile with the -P driver option to prepro-
cess assembly files, see Section 4.8.11 “-P: Preprocess Assembly Files”.
The symbols in this header file look similar to the identifiers used in the C domain when
including <xc.h>, e.g., PORTA, EECON1, etc. They are different symbols in different
domains, but will map to the same memory location.
including <xc.h>, e.g., PORTA, EECON1, etc. They are different symbols in different
domains, but will map to the same memory location.
Bits within registers are defined as the registerName,bitNumber. So for example,
RA0
RA0
is defined as PORTA,0.
Here is an example of a mid-range assembly module that uses SFRs.
#include <xc.inc>
GLOBAL _setports
PSECT text,class=CODE,local,delta=2
_setports:
MOVLW
0xAA
BANKSEL
(PORTA)
MOVWF
BANKMASK(PORTA)
BANKSEL
(PORTB)
BSF
RB1