SW500009 Microchip Technology, SW500009 Datasheet - Page 81

HI-TECH FOR DSPIC/PIC24

SW500009

Manufacturer Part Number
SW500009
Description
HI-TECH FOR DSPIC/PIC24
Manufacturer
Microchip Technology
Type
Compilerr
Series
PIC24 & DsPICr
Datasheet

Specifications of SW500009

Supported Families
PIC24
Core Architecture
PIC, DsPIC
Software Edition
Standard
Kit Contents
Software And Docs
Tool Type
Compiler
Mcu Supported Families
PIC24 MCUs And DsPIC DSCs
Lead Free Status / RoHS Status
Not applicable / RoHS Compliant
For Use With/related Products
DSPIC3X/PIC24
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
Other names
025
778-1003
778-1003
C Language Features
A mapping is performed on the names of all C functions and non-static global variables. See
Section
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 quantity.
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 executable 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 text0, will be
linked in the CODE class, which will reside in a memory space that has 2 bytes per addressable
location:
_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
associate with the assembly code:
sembly routine, we can determine the signature value. We add a assembler directive to make this
signature value known:
parameter area by the calling function, and the result should be placed in btemp.
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.
sembler routine, then calls the routine.
An assembly routine is required which can add two 16-bit values together. The routine must be
Most compiler-generated executable code is placed in a psect called textn (see Section 3.9.1).
PSECT text0,local,class=CODE,delta=2
Now we would like to call this routine add. However in assembly we must choose the name
_add:
We need to be able to call this from other modules, some make this label globally accessible:
GLOBAL _add
By compiling a dummy C function with a similar prototype to how we will be calling this as-
SIGNAT _add,8298
When writing the function, you can find that the parameters will be loaded into the function’s
To call an assembly routine from C code, a declaration for the routine must be provided. This
If a signature value is present in the assembly code routine, its value will be checked by the linker
To continue the previous example, here is a code snippet that declares the operation of the as-
write the routine ensuring arguments are read from the correct location, the return value is
loaded to the correct storage location before returning
ensure any local variables required by the routine have space reserved by the appropriate
directive
3.11.3.1
for a complete description of mappings between C and assembly identifiers.
Mixing C and Assembler Code
67

Related parts for SW500009