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 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, the banksel determines the bank of the desired memory location, then configures the MOVLB instruction appropriately for the bank.
Example code:
The following code shows two methods of loading the 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.