MPASM to MPLAB XC8 PIC Assembler - b

bankmask and banksel
old Alternate Products
PIC16F84-1998 pic18f26q10
PIC16F877a-2001 PIC16F18877

bankmask - macro

It is recommended that you mask all addresses used by PIC file register instructions whose operand represents a bank offset.

#include <xc.inc>
copy:
  BANKSEL (src)              ;select the bank of src
  movf     BANKMASK(src),w   ;move from src, masking the address
  BANKSEL (dst)              ;select the bank of dst
  movwf    BANKMASK(dst)     ;move to dst, masking the address

The BANKMASK() macro, can perform the mask using the correct values, based on the selected device.

banksel - Pseudo-instructions

The file registers of the pic are held in banks, some are shared across all banks and some program data can also be shared across all banks but this is obviously wasteful of memory so it’s limited to select registers and shared data.

Special function registers, SFR’s are used to control, configure and check the pic’s status.
These tend to be on different banks to the programs variables so you need to change banks or your program will be accessing the wrong bank.
This is where the ‘banksel’ instruction comes in. It makes sure you are addressing the correct memory bank.

When to use banksel

  • first access of any UDATA section variable
  • first access of register after a subroutine call/external module
  • when accessing a banked special function register
  • after having accessed a banked SFR(special function register)

When to don’t need to use banksel

  • after first access to a UDATA variable other UDATA variables are in the same bank
  • UDATA_SHR variables are available on any bank
  • accessing Non-banked SFR’s like STATUS etc.. can be done from any bank

Ref