When addressing memory directly, the Effective Address is calculated using two pieces of information:
- The run-time content of the Bank Select Register (BSR)
- The executing instruction's 7-bit operand
Assembly language programmers must ensure that the BSR (Bank Select Register) is loaded with the proper bank number for the desired memory location. The assembly language instruction MOVLB is the instruction specifically provided by MPASM for loading the BSR.
The assembler DIRECTIVE banksel can also be used to load the BSR. At compile time banksel determines the bank of the desired memory location, then configures the MOVLB instruction appropriately for the bank.
The code below shows two methods of loading BSR in assembly language. The first example uses banksel to automatically calculate the BSR. The second example manually calculates the appropriate BSR value.
Users of the MPLAB XC8 C compiler do not need to be directly concerned with banking. Assignment statements will result in the compiler and linker calculating and inserting the needed MOLVB instructions.