4.1 Assembler Macros

An assembler macro was defined and used in this chapter's example program.

Assembler macros perform a similar function to the preprocessor's #define directive, in that they define a single identifier to represent a sequence of code. When a large amount of code spread over multiple lines is to be represented, assembler macro definitions might be easier to read than preprocessor macros.

In this chapter's example, the macro is defined to represent just one instruction, and is as shown here.
skipnc  MACRO
	btfsc     CARRY
ENDM

This creates a macro that skips the following instruction based on the carry bit in the STATUS register. Bit access of SFRs is described later, in section Defining And Using Bits.

This macro is used just the once in this example, repeated here:
	subwf      max^(tmp&0ff80h),w
	skipnc
	goto       loop

An assembler macro can have arguments, too, and there are several characters that have special meaning inside macro definitions. A full description of these are presented in the MPLAB® XC8 PIC Assembler User's Guide.