SW500008 Microchip Technology, SW500008 Datasheet - Page 85

PICC-18 STD

SW500008

Manufacturer Part Number
SW500008
Description
PICC-18 STD
Manufacturer
Microchip Technology
Type
Compilerr
Series
PIC18r
Datasheets

Specifications of SW500008

Supported Families
PIC18
Core Architecture
PIC
Software Edition
Standard
Kit Contents
Software And Docs
Mcu Supported Families
PIC18
Tool Function
Compiler
Tool Type
Compiler
Lead Free Status / RoHS Status
Not applicable / RoHS Compliant
For Use With/related Products
PIC18 Series
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
Other names
015
778-1001
778-1001
C Language Features
3.11.2 Accessing C objects from within Assembly Code
Global C objects may be directly accessed from within assembly code using their name prepended
with an underscore character. For example, the object foo defined globally in a C module:
may be access from assembler as follows.
If the assembler is contained in a different module, then the GLOBAL assembler directive should be
used in the assembler code to make the symbol name available, as above. If the object is being
accessed from in-line assembly in another module, then an extern declaration for the object can be
made in the C code, for example:
This declaration will only take effect in the module if the object is also accessed from within C code.
If this is not the case then, an in-line GLOBAL assembler directive should be used. Care should be
taken if the object is defined in a bank other than 0. The address of a C object includes the bank
information which must be stripped before the address can be used in most PIC18 instructions. The
exceptions are the movff and lsfr instructions. Failure to do this may result in fixup errors issued
by the linker. If in doubt as to writing assembler which accesses C objects, write code in C which
performs a similar task to what you intend to do and study the assembler listing file produced by the
compiler.
T
To continue the previous example, here is a code snippet that declares the operation of
the assembler routine, then calls the routine.
extern unsigned int add(unsigned a, unsigned b);
void main(void)
{
}
int foo;
GLOBAL _foo
movwf
extern int foo;
UT RIAL
int a, result;
a = read_port();
result = add(5, a);
_foo
Mixing C and Assembler Code
71

Related parts for SW500008