Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#1396 PIC16:wrong __data pointer initialization on two-dim. arrays

open
nobody
PIC16
5
2013-07-16
2007-11-17
No

Version: last MINGW32 available
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.7.0 #4818 (May 31 2007) (MINGW32)

command line:
sdcc -c -mpic16 -p18f6720 -V --std-sdcc99 --verbose --model-small -o"test.rel" "test.c"

Problem:
if one pointer variable initialized twice or more in one function, pointing to non-first line of two-dimensional array, wrong initialization code produced:
<pre>
pTmp1 = Data[1];
x = 8; do { *pTmp1++ = 0x01; } while(--x);

pTmp1 = Data[4];
x = 8; do { *pTmp1++ = 0x80; } while(--x);

; .line 13; test.c pTmp1 = Data[1];
MOVLW 0x08
BANKSEL LOW(_Data)
ADDWF LOW(_Data), W, B
MOVWF r0x00
MOVLW 0x00
BANKSEL HIGH(_Data)
ADDWFC HIGH(_Data), W, B
MOVWF r0x01
.............
</pre>using different pointer variables results in correct code:<pre>
pTmp1 = Data[1];
x = 8; do { *pTmp1++ = 0x01; } while(--x);

pTmp2 = Data[4];
x = 8; do { *pTmp2++ = 0x80; } while(--x);

MOVLW LOW(_Data + 8)
MOVWF r0x00
MOVLW HIGH(_Data + 8)
MOVWF r0x01
MOVLW 0x08
MOVWF r0x02
</pre>

Discussion

  • pic16 pointer initialization bug.

     
    Attachments
  • Maarten Brock
    Maarten Brock
    2011-09-18

    • summary: wrong data pointer initialization on two-dim. arrays --> PIC16:wrong data pointer initialization on two-dim. arrays
     
    • Category: --> PIC16