Address Masking

A file register address used with most instructions should be masked to remove the bank information from the address. Failure to do this might result in a linker fixup error.

All MPLAB XC8 assembly identifiers represent a full address. This address includes the bank information for the object it represents. Virtually all instructions in the 8-bit PIC instruction sets that take a file register operand expect this operand value to be an offset into the currently selected bank. As the device families have different bank sizes, the width of this offset is different for each family.

The BANKMASK() macro can be used with identifier or address operands. The macro ANDs out the bank information in the address using a suitable mask. It is available once you include <xc.inc>. Use of this macro increases assembly code portability across Microchip devices, since it adjusts the mask to suit the bank size of the target device. An example of this macro is given in Bank And Page Selection.

Do not use this macro with any instruction that expects its operand to be a full address, such as the PIC18’s movff instruction.