Although C has a wide range of operators, it can sometime lack functionality dedicated to embedded programming, and it certainly will not provide device-specific operations or code sequences.
When faced with a requirement for an operation that is not handled by the C language, the temptation is to immediate dust off your device data sheet and program in assembly code. Before you venture down this path, first check to make sure that there is not already a compiler built-in function provided that can perform the task you require.
All three Microchip MPLAB® XC compilers provide built-in functions, and these offer several benefits over hand-written assembly code.
Built-in functions differ from ordinary C functions in that the assembly code they generate directly implements the desired task. Since there is no call, return, or parameter passing, they are very efficient, yet they provide the same code abstraction provided by functions and make understanding source code easier. Optimizations are typically enabled for the output of built-in functions, unlike in-line assembly code, and register usage of built-in functions is taken into consideration by the compiler, which ensures that the code works with the surrounding compiler-generated code—a common failure of handwritten in-line assembly code.
Examples of the tasks performed by built-in functions include in-line delays, software breakpoints, enabling and disabling interrupts, bit operations, arithmetic operations, program memory access, and peripheral unlock sequences.
Check the Appendixes in your compiler’s User’s Guide to find out what built-in functions are available and what they do.
Microchip Technology acquires Atmel