XC8 and mixed assembly/C code for a PIC16F876A and banksel translation into the lst output
I've ported an old program from a Hi-Tech PICC v8.05 PL2 to the XC8 v1.45 inside the MPLABX IDE v5.15.
All compile without trouble but the final application work not properly regarding the aseembly coded section.
To perform the port I've used the BANKSEL and BANKMASK directive, but into the final listing file I can not correctly understand in what way these ones are translated, for example, look at this piece of code (a simple delay subroutine):
movlw DELAY_4700NS ;
movwf BANKMASK(_Delayctr) ;
decfsz BANKMASK(_Delayctr),f ;
goto Loop_tbuf ;
is compiled as (from lst file):
9086 ;psect for function _Delay_tbuf
9087 17F0 _Delay_tbuf:
9089 ;incstack = 0
9090 ; Regs used in _Delay_tbuf: 
9091 17F0 3004 movlw 4 ; #
9092 17F1 1303 1683 banksel _Delayctr ;#
9093 17F3 00DC movwf _Delayctr& (0+127) ; #
9094 17F4 Loop_tbuf:
9097 17F4 0BDC decfsz _Delayctr& (0+127),f ; #
9098 17F5 2FF4 goto Loop_tbuf ;#
9100 ;i2c.c: 139: return;
9101 17F6 0008 return
9102 17F7 __end_of_Delay_tbuf:
I can not see the expansion into the code of the "banksel" directive, this should be like a bsf/bcf instruction, there is a way to set the linker to produce a full listing code with all the asm istruction inside?
Also, into the old compiler all the variable used inside the assembly was set into the bank0 "psect rbss_0", inside the XC8 all was moved inside the "psect bssBANK1" so there is a need to perform the switch into the correct bank, what should be the best way to force allocation of these variable inside the bank0?
I've also another suspect concerning the use of the sequence btfsc or btfss and the banksel directive, as example look at this code (working, on bank0):
for the code inside the XC8 (not workin) I've instead:
bsf _EE_Error_Flag& (0+127),0
btfsc _EE_Error_Flag& (0+127),0
the last (not working) code will have more instruction after btfsc 7,4 due to the BANKSEL macro so I think that the flow will be messed respect the original version where no bank switch was needed, I'm right? If this is the real reason why the code is not properly working I've to change the code structure around any btfsc/banksel isnstructions sequence, I'm right?
post edited by TechDpt - 2019/08/14 11:04:13