Direct Addressing
When addressing memory directly, the Effective Address (EA) 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 directive 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.
|
1
2 1 2 |
banksel TRISC ; set BSR to the bank with TRISCclrf TRISC ; clear TRISC -------------------------------------------------- molvb 2 ; load BSR with the literal value 2clrf LATC ; clear LATC |
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.