
Originally Posted by
sougata
Although it is not the case for this prog, but I need to know. Can you please.... explain a more as I do not know much about PBP internals.
I can try ...
I guess the biggest problem is with CHK?RP and RST?RP.
Each time they're used, it saves it's result to an ASM variable called PREV_BANK.
And the next time one's used, CHK?RP uses that PREV_BANK value to figure out if it needs to change the bank ... and if so ... which bits need to be set to use the least amount of code space.
Using BANKSEL or setting the bank manually does not update the PREV_BANK variable, so PBP can get lost from not knowing which bank it's really in.
Even GOTO's within an area of code that only uses CHK?RP can be problems.
For instance with this code ...
Code:
MyVar0 VAR BYTE BANK0
MyVar1 VAR BYTE BANK1
ASM
CHK?RP _MyVar1 ; 1 - this will select BANK1
movlw 12
xorwf _MyVar1,W
btfss STATUS,Z
goto Bypass
CHK?RP _MyVar0 ; 2 - this selects BANK0
btfss _MyVar0,5
goto ExitRoutine
Bypass
CHK?RP _MyVar0 ; 3 - This statement does nothing. Although the intent
movlw 34 ; was to change to BANK0, the PREV_BANK from the
movwf _MyVar0 ; last CHK?RP at step 2 says we're already in BANK0.
goto AnotherPlace ; But if we got here from the goto Bypass in step 1 ...
; then BANK1 is still selected, and it will overwrite
; the wrong RAM location in BANK1.
ExitRoutine
ENDASM
PREV_BANK works line by line from the top of the program.
GOTO's can bypass that logic.
There are many different variations of the same problem, and BANKSEL or manually setting STATUS or BSR bits will only make it worse.
Once you know how it works ... of course ... it's a piece of cake.
Some of the ways around the problems are to use the LABEL?L, L?GOTO and L?CALL macros.
<br>
Clear as MUD.
Bookmarks