#8 Pb with & operator and array

closed-fixed
Sandeep Dutta
5
2000-06-14
2000-05-22
Anonymous
No

Hey,

I found a bug with & operator in V2.2.0a, see detail below :

xdata at 0 void PTR_NULL[0];

struct sEMN {
unsigned char prec;
unsigned char suiv;
unsigned int xy;
code char * code cdata;
};

volatile unsigned char iMenu;
static code struct sEMN * p;
code struct sEMN code chaineMENU[5][4] = {
{{0x00,0x01,0x00,PTR_NULL},{0,0,0,PTR_NULL},{0,0,0,PTR_NULL},{0,0,0,PTR_NULL}},
{{0x00,0x01,0x00,PTR_NULL},{0,0,0,PTR_NULL},{0,0,0,PTR_NULL},{0,0,0,PTR_NULL}},
{{0x00,0x01,0x00,PTR_NULL},{0,0,0,PTR_NULL},{0,0,0,PTR_NULL},{0,0,0,PTR_NULL}},
{{0x00,0x01,0x00,PTR_NULL},{0,0,0,PTR_NULL},{0,0,0,PTR_NULL},{0,0,0,PTR_NULL}},
{{0x00,0x01,0x00,PTR_NULL},{0,0,0,PTR_NULL},{0,0,0,PTR_NULL},{0,0,0,PTR_NULL}}
};

//********************************************
void fn1(void){

// Code generated for this line is wrong with V2.2.0a
p = & chaineMENU[iMenu&0x0f][iMenu>>4];
// ...
}

;--------------------------------------------------------
; File Created by SDCC : FreeWare ANSI-C Compiler
; Version 2.1.9Ga Mon May 22 14:08:24 2000

; function fn1
; -----------------------------------------
_fn1:
C$tst.c$194$1$1 ==.
; tst.c 194
mov a,#0x0f
anl a,_iMenu
mov b,#0x18
mul ab
; Peephole 105 removed redundant mov
; Peephole 215 removed some movs
add a,#_chaineMENU
mov r2,a
; Peephole 180 changed mov to clr
clr a
addc a,#(_chaineMENU >> 8)
mov r3,a
mov a,_iMenu
swap a
anl a,#0x0f
mov r4,a
mov b,#0x06
mov a,r4
mul ab
; Peephole 105 removed redundant mov
mov r4,a
add a,r2
mov _p,a
; Peephole 180 changed mov to clr
clr a
addc a,r3
mov (_p + 1),a
00101$:
C$tst.c$196$1$1 ==.
XG$fn1$0$0 ==.
ret
G$main$0$0 ==.
C$tst.c$199$1$1 ==.
; tst.c 199

;--------------------------------------------------------
; File Created by SDCC : FreeWare ANSI-C Compiler
; Version 2.2.0 Mon May 22 14:09:40 2000

// Code generated is wrong

_fn1:
C$tst.c$194$1$1 ==.
; tst.c 194
mov a,#0x0f
anl a,_iMenu
mov b,#0x18
mul ab
; Peephole 105 removed redundant mov
mov r2,a
add a,#_chaineMENU
mov dpl,a
; Peephole 180 changed mov to clr
clr a
addc a,#(_chaineMENU >> 8)
mov dph,a
mov a,_iMenu
swap a
anl a,#0x0f
mov r2,a
clr a
movc a,@a+dptr
mov r3,a
inc dptr
clr a
movc a,@a+dptr
mov r4,a
mov b,#0x18
mov a,r2
mul ab
; Peephole 105 removed redundant mov
mov r2,a
add a,r3
mov _p,a
; Peephole 180 changed mov to clr
clr a
addc a,r4
mov (_p + 1),a
00101$:
C$tst.c$196$1$1 ==.
XG$fn1$0$0 ==.
ret
G$main$0$0 ==.
C$tst.c$199$1$1 ==.
; tst.c 199

Discussion

  • Sandeep Dutta
    Sandeep Dutta
    2000-06-14

    Fixed . In current tree . & 2.2.1

     
  • Sandeep Dutta
    Sandeep Dutta
    2000-06-14

    • assigned_to: nobody --> sandeep
    • status: open --> closed-fixed