11.6 Mixing C and Assembly Language Code
The MPLAB XC16 C compiler generates fixed-point code that assumes that certain 16-bit device resources are managed by the compiler's start-up and run-time code. Hand-written assembly code built into the same program could interfere with the state of the CPU assumed by the code the compiler generates.
MPLAB XC16 programs may contain both fixed-point C and assembly language
code that utilizes 16-bit device intrinsic fixed-point capabilities directly, but in order
for these two kinds of code to inter-operate safely, the compiler must save certain dsPIC
registers around calls to assembly language functions that may change their state. The C
compiler can be instructed to do so by providing prototypes for assembly language functions
for which this is necessary. These prototypes should specify the
save(CORCON)
attribute for the target assembly language function, as
described in the Function Attributes
section. Programs constructed in this manner will operate correctly, at the expense of some
state saves and restores around calls to the indicated assembly routines.