How Should I Combine Assembly And C Code?

Ideally, any hand-written assembly should be written as separate routines that can be called. This offers some degree of protection from interaction between compiler-generated and hand-written assembly code. Such code can be placed into a separate assembly module that can be added to your project (see Integrating Assembly Language Modules).

If necessary, assembly code can be added in-line with C code (see Inline Assembly). The code added in-line should ideally be limited to instructions such as nop, sleep or clrwdt. Macros are already provided which in-line all these instructions (see, for example, NOP Macro). More complex in-line assembly that changes register contents and the device state can cause code failure if precautions are not taken, and such assembly should be used with caution. See Register Usage for those registers used by the compiler.