SW500007 Microchip Technology, SW500007 Datasheet - Page 84

PICC-18 PRO

SW500007

Manufacturer Part Number
SW500007
Description
PICC-18 PRO
Manufacturer
Microchip Technology
Type
Compilerr
Series
PIC18r
Datasheets

Specifications of SW500007

Supported Families
PIC18
Core Architecture
PIC
Software Edition
Professional
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
015P
778-1002
778-1002
Mixing C and Assembler 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 paramters and return
values, however no other code is necessary.
when the calling and called routines’ signatures can be compared.
70
If a signature value is present in the assembly code routine, its value will be checked by the linker
T
An assembly routine is required which can add two 16-bit values together. The routine
must be callable from C code. Both the values are passed in as arguments when the
routine is called from the C code. The assembly routine should return the result of the
addition as a 16-bit quanity.
Most compiler-generated executable code is placed in a psect called text (see Section
3.9.1). As we do not need to have this assembly routine linked at any particular location,
we can use this psect so the code is bundled with other executbale code and stored
somewhere in the program space. 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 text, will be linked in the CODE class,
which will reside in a memory space that has 1 bytes per addressable location:
PSECT text,local,class=CODE,delta=1
Now we would like to call this routine add. However in assembly we must choose the
name _add as this then maps to the C identifier add since the compiler prepends an
underscore to all C identifiers when it creates assembly labels. If the name add was
chosen for the assembler routine the it could never be called from C code. The name of
the assembly routine is the label that we will assocaite with the assembly code:
_add:
We need to be able to call this from other modules, so make this label globally access-
able:
GLOBAL _add
By compiling a dummy C function with a similar prototype to how we will be calling
this assembly routine, we can determine the signature value. We add an assembler
directive to make this signature value known:
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
btemp.
UT RIAL
C Language Features

Related parts for SW500007