SW500011 Microchip Technology, SW500011 Datasheet - Page 90

HI-TECH X PRO FOR PIC32

SW500011

Manufacturer Part Number
SW500011
Description
HI-TECH X PRO FOR PIC32
Manufacturer
Microchip Technology
Type
Compilerr
Series
PIC32r
Datasheet

Specifications of SW500011

No. Of User Licenses
1
Supported Families
PIC32
Core Architecture
PIC
Supported Hosts
Windows XP, Vista, Linux, Mac OS X
Software Edition
Professional
Kit Contents
Software And Docs
Tool Type
Compiler
Lead Free Status / RoHS Status
Not applicable / Not applicable
For Use With/related Products
PIC32 Series
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
Other names
032
778-1007
778-1007
Mixing C and Assembly Code
To call an assembly routine from C code, a declaration for the routine must be provided. This ensures
that the compiler knows how to encode the function call in terms of parameters and return values,
however no other code is necessary.
when the calling and called routines’ signatures can be compared.
90
If a signature value is present in the assembly code routine, its value will be checked by the linker
This way we do not need to use any additional linker options. So we use an ordinary
looking psect that you would see in assembly code produced by the compiler. The
psect’s name is text32. It will be linked somewhere in the range of addresses defined
by the CODE class:
PSECT text32,class=CODE
Now we would like to call this routine as add in the C code. Thus, in assembly code, we
must choose the name _add as this then maps to the C identifier add. If the name add
was chosen for the assembly routine label, then it could never be called from C code.
The name of the assembly routine is the label that we will associate with the assembly
code:
_add:
We need to be able to call this from other modules, so make this label globally accessi-
ble:
GLOBAL _add
By compiling a dummy C function with a similar prototype to the prototype we require
for our function add, we can determine the signature value. To see the value, generate
an assembly list file, and compile with the assembler optimizer turned off. Look for a
directive similar to that below, which can then be copied into the assembly source for
our add routine.
SIGNAT _add,8298
When writing the function, you can find that the parameters will be loaded into the
function’s parameter area by the calling function, and the result should be placed in the
same location to be returned.
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 short add(unsigned short a, unsigned short b);
void main(void)
UT RIAL
C Language Features

Related parts for SW500011