I am working on an open source project, an IDE for SDCC. And emulator for mcs51/pic16/pic18.
Here is the github address:
https://github.com/athenajc/XideSDCC
I found divuchar and moduchar access 0x7f didn't switch bank.
Here is the sample code.
#include <pic16f628a.h>
void main(void)
{
unsigned char i;
for (i = 3; i < 16; i++)
{
PORTA = i % 3;
PORTB = i / 3;
}
}
__divuchar:
0000D2 1283 bcf STATUS,5 <--- here had switch to bank 2
0000D3 1703 bsf STATUS,6
0000D4 00AC movwf 0x2c
0000D5 087F movf 0x7f,w <--- STK00 is at 0x7f
0000D6 00AD movwf 0x2d
0000D7 01AE clrf 0x2e
0000D8 3001 movlw 0x1
0000D9 00AF movwf 0x2f
0000DA 082D movf 0x2d,w
0000DB 1D03 btfss STATUS,2
0000DC 28DF goto _00107_DS_
0000DD 30FF movlw 0xff
0000DE 2902 goto _00115_DS_
_moduchar:
0000B9 1283 bcf STATUS,5
0000BA 1703 bsf STATUS,6
0000BB 00AC movwf 0x2c
0000BC 087F movf 0x7f,w
0000BD 00AD movwf 0x2d
0000BE 082D movf 0x2d,w
0000BF 1D03 btfss STATUS,2
0000C0 28C3 goto _00119_DS_
0000C1 30FF movlw 0xff
0000C2 2902 goto _00115_DS_
For this reason no need to switch bank. The 0x70-0x7F area can be achieved same place in each bank. See it the Complete Mid-Range Reference Manual document on the 103 side.
This old bug should be closed as invalid.
It's well known to all PIC programmers that 0x70 to 0x7F at the end of a memory bank is "common RAM" and these bytes are globally accessible from all banks. For example, SDCC currently uses it as a software stack STK00 to STK15 for passing arguments across different memory banks.
Last edit: Tom Li 2023-01-03
Alright. Let's close it.