#224 Bad code gen for 8-bit array index

closed-fixed
nobody
None
5
2013-05-25
2001-11-13
Alex Karahalios
No

The following C code generates incorrect ASM code. This is for SDCC in CVS:

typedef struct _S_ {
unsigned char INDEX;
unsigned char ARRAY[];
} S;

xdata S DATA;

void main (void)
{
DATA.ARRAY[DATA.INDEX] = 1;
}

; main.c 10
; genPointerGet
; genFarPointerGet
mov dptr,#_DATA
movx a,@dptr
mov r2,a
inc dptr
movx a,@dptr
mov r3,a
; genPlus
mov a,r2
add a,#(_DATA + 0x0001)
mov dpl,a
mov a,r3
addc a,#((_DATA + 0x0001) >> 8)
mov dph,a
; genPointerSet
; genFarPointerSet
mov a,#0x01
movx @dptr,a

As you can see the code generator assumed that the index was 16 bits when in fact it is only 8 bits.

Thanks,

Alex Karahalios

Discussion

  • Sandeep Dutta
    Sandeep Dutta
    2001-11-14

    • milestone: --> fixed
    • status: open --> closed-fixed