Compilation of Assembly Source

Assembly source files that are part of a C project are compiled in a similar way to C source files. The compiler driver knows that these files should be passed to a different set of internal compiler applications and a single build command can contain a mix of C and assembly source files, as in the following example.

xc8-cc -mcpu=16F877A proj.c spi.s

If an assembly source file contains C preprocessor directives that must be preprocessed before passed to the assembler, then ensure the source file uses a .S extension, for example spi.S.

The compiler can be used to generate assembly files from C source code using the -S option. The assembly output can then be used as the basis for your own assembly routines and subsequently compiled using the command-line driver.

MPLAB XC8 builds assembly source files before C source files, so that information contained in the assembly code can be subsequently passed to the code generator, see Interaction between Assembly and C Code.

The intermediate file format associated with assembly source files is an object file (.o extension). The -c option (see C: Compile To Intermediate File) will halt compilation after the assembly step when building assembly source files, generating the object file.