This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

program thinking 019c and 009c are equal

the code is as follows:

the declaration of two global variables:
unsigned short int xdata x;
unsigned char xdata META_TEDS[MAXINBUFF];
/*MAXINBUFF = 128*/

later in a function I have:
for( x=2;x<12;x++ ){
printf( "UUID %d\r\n", x );
printf( "UUID address %p\r\n", &x );
printf( "META_TEDS address %p\r\n", &META_TEDS[x] );
META_TEDS[x]=_getkey( );
printf( "UUID %d\r\n", x );
printf( "UUID address %p\r\n", &x );
printf( "META_TEDS address %p\r\n", &META_TEDS[x] );
}

all works well until the iteration where &META_TEDS[x] = 009c. here is what i get output in hyperterm:

/*previous iterations are correct*/

UUID 8
UUID address x:019c
META_TEDS address x:009a
UUID 8
UUID address x:019c
META_TEDS address x:009a
UUID 9
UUID address x:019c
META_TEDS address x:009b
UUID 9
UUID address x:019c
META_TEDS address x:009b
UUID 10
UUID address x:019c
META_TEDS address x:009c
UUID 12554
UUID address x:019c
META_TEDS address x:009c

the iteration where x=10 is where the problem lies. under default and OPTIMIZE(0) it behaves the same. the assembly for the code segment "META_TEDS[x]=_getkey( );" is as follows:

; SOURCE LINE # 84
00AD 120000 E LCALL _getkey
00B0 900000 E MOV DPTR,#x+01H
00B3 E0 MOVX A,@DPTR
00B4 FE MOV R6,A
00B5 7400 E MOV A,#LOW META_TEDS
00B7 2E ADD A,R6
00B8 F582 MOV DPL,A
00BA E4 CLR A
00BB 3400 E ADDC A,#HIGH META_TEDS
00BD F583 MOV DPH,A
00BF EF MOV A,R7
00C0 F0 MOVX @DPTR,A

it seems that in the above segment during the said iteration what _getkey() retrieves is put into 019c (x) instead of 009c (META_TEDS[x]).

-Nathan

Parents Reply Children
No data