3.3.7.5 What Things Must I Manage When Writing Assembly Code?
There are several things that you must manage if you are hand-writing assembly code.
- You must place any assembly code you write into a section. See the
“Linker Processing” chapter of the “MPLAB® XC32 Assembler, Linker and
Utilities User’s Guide” (DS50002186) for more
information.
Assembly code that is placed in-line with C code will be placed in the same section as the compiler-generated assembly and you should not place this into a separate section.
- You must ensure that any registers you write to in assembly code are not already in use by compiler-generated code. If you write assembly in a separate module, then this is less of an issue as the compiler will, by default, assume that all registers are used by these routines (see 14.1 Register Usage, registers). No assumptions are made for in-line assembly (see 20.1 Mixing Assembly Language and C Variables and Functions) and you must be careful to save and restore any resources that you use (write) and which are already in use by the surrounding compiler-generated code.