11.07.2015 Views

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Mixing C and Assembler CodeC Language Features3.11.1 External Assembly Language FunctionsEntire functions may be coded in assembly language as separate .as source files, assembled andcombined into the output image using the linker. This technique allows arguments and return valuesto be passed between C and assembler code.The following are guidelines that must be adhered to when writing a routine in assembly codethat is callable from C code.• select, or define, a suitable psect for the executable assembly code• select a name (label) for the routine so that its corresponding C identifier is valid• ensure that the routine’s label is globally accessable from other modules• select an appropriate equivalent C prototype for the routine on which argument passing can bemodelled• ensure any symbol used to hold arguments to the routine is globally accessable• ensure any symbol used to hold a return value is globally accessable• optionally, use a signature value to enable type checking when the function is called• write the routine ensuring arguments are read from the correct location, the return value isloaded to the correct storage location before returning• ensure any local variables required by the routine have space reserved by the appropriatedirectiveA mapping is performed on the names of all C functions and non-static global variables. SeeSection 3.11.3.1 for a complete description of mappings between C and assembly identifiers.50TUT•RIALA assembly routine is required which can add two 16-bit values together. The routinemust be callable from C code. Both the values are passed in as arguments when theroutine is called from the C code. The assembly routine should return the result of theaddition as a 16-bit quanity.Most compiler-generated executable code is placed in a psect called text (see Section3.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 storedsomewhere in the program space. This way we do not need to use any additional linkeroptions. So we use an ordinary looking psect that you would see in assembly code

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!