3.4 Commonly Used Directives

There are several assembler directives that are typically used in each module. These have been used in the example code for this chapter and are discussed here.

Processor Directive

The PROCESSOR directive is not mandatory but should be used if the assembler source in the module is only applicable to one device.

The -mcpu option always specifies which device the code is being built for. If the PROCESSOR directive has been used and there is a mismatch between the device specified in that directive and in the option, an error will be triggered. The line of code:
PROCESSOR 18F47K42
shows the PIC18F47K42 device being specified. With this in place, the code cannot be built for any other device.
If your code can be built for multiple devices, the PROCESSOR directive should be omitted. You can instead make sections of your code specific to the target device by using the preprocessor's conditional inclusion features and preprocessor macros predefined by the PIC Assembler. For example:
#ifdef _18F47K40
  movwf LATE
#endif
will assemble the movwf instruction only for PIC18F47K40 devices. The _18F47K40 preprocessor macro is one that is automatically defined by the assembler, based on the device selected by the -mcpu option. A full list of predefined macros is available in the MPLAB® XC8 PIC Assembler User's Guide.

End Directive

Use of the END directive is not mandatory, but signifies an end to the source code in that module. There can be no further lines of source present after an END directive, even blank ones.

If you use one or more END directives in your program, one (and only one) of those directives should specify the program's entry point label to prevent an assembler warning being generated. This has been done in the last line of the example program:
END resetVec