The following code results in an unsupported generic pointer, which later will cause ptrput1.c to corrupt the stack
__sfr __at (0x666) MMM;
void main() {
unsigned char *pb[3];
pb[1] = (unsigned char *) &MMM;
}
generates the following assembly:
.line 63; evd5master.c pb[1] = (unsigned char *) &MMM;
MOVLW 0x66
BANKSEL (_main_pb_2_2 + 3)
MOVWF (_main_pb_2_2 + 3), B
MOVLW 0x06
BANKSEL (_main_pb_2_2 + 4)
MOVWF (_main_pb_2_2 + 4), B
BANKSEL (_main_pb_2_2 + 5)
CLRF (_main_pb_2_2 + 5), B
Note the last line sets the generic pointer MSB to zero instead of 0x80.
unsigned char *ptr = (unsigned char *) &MMM; does not have the same problem.
The attached evd5master.c demonstrates this problem. Note the 00 06 66 on the the 4th line.
00000000 73 74 61 72 74 75 70 20 20 20 20 20 20 20 20 20 |startup |
00000010 36 36 36 20 20 20 20 20 80 06 66 20 20 20 20 20 |666 ..f |
00000020 36 36 36 20 20 20 20 20 80 06 66 20 20 20 20 20 |666 ..f |
00000030 36 36 36 20 20 20 20 20 00 06 66 20 20 20 20 20 |666 ..f |
00000040 36 36 36 20 20 20 20 20 80 06 66 20 20 20 20 20 |666 ..f |
sdcc -mpic16 -p18f2682 -V --debug -c evd5master.c
sdcc -mpic16 -p18f2682 -V --debug -Wl-c -Wl-m -oevd5master.hex evd5master.o /usr/share/sdcc/lib/pic16/libc18f.lib
SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.9.0 #5416 (Aug 15 2009) (UNIX)
demonstration of pointer generic pointer MSB loss