3.3.7.1 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 5.12.1 Integrating Assembly Language Modules).

If necessary, assembly code can be added in-line with C code (see 5.12.2 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, 9.2.19 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 5.6 Register Usage for those registers used by the compiler.