Hi Thln, I'm no expert, but the most common reason for this sort of
thing is gcc optimization, and the most common cure is to declare the
index volatile, so you might try declaring i volatile.
Hope it helps,
Garst
thln wrote:
Hi,
Thanks, Chris Liechti, for your help about _Re: Help about sizeof(
struct ...) MSP430-GCC_ (2005-04-26 16:46)
So, if i write the fowling function (Swap_TAB_UART), the result is not
good.
the function lose len, ix values.
It seems that the C compiler overwrites registers !!!
Kind Regards, Thln!
void Swap_TAB_UART(unsigned char ix, unsigned char len)
{
unsigned char i, tmp, l;
l = len/2;
i = 0;
do
{
tmp = TAB_UART[ix+i];
TAB_UART[ix+i] = TAB_UART[ix+len-i-1];
TAB_UART[ix+len-i-1] = tmp;
i++;
} while (i<l);
}
void main(void)
{
TAB_UART[15] = 0xC1;
TAB_UART[16] = 0x20;
TAB_UART[17] = 0x00;
TAB_UART[18] = 0x00;
Swap_TAB_UART(15, 4);
}
void Swap_TAB_UART(unsigned char ix, unsigned char len)
{
cd10: 0b 12 push r11 ;
cd12: 0a 12 push r10 ;
cd14: 09 12 push r9 ;
cd16: 08 12 push r8 ;
cd18: 04 12 push r4 ;
cd1a: 4d 4f mov.b r15, r13 ; R13 = ix
cd1c: 4f 4e mov.b r14, r15 ; R15 = len
unsigned char i, tmp, l;
l = len/2;
cd1e: 49 4e mov.b r14, r9 ;
cd20: 12 c3 clrc
cd22: 49 10 rrc.b r9 ; R9= len/2
i = 0;
cd24: 4c 43 clr.b r12 ; R12=i
cd26: 4e 4d mov.b r13, r14 ;
cd28: 7f f3 and.b #-1, r15 ;r3 As==11
do
cd2a: 38 40 20 02 mov #544, r8 ;#0x0220
cd2e: 0a 4e mov r14, r10 ;
cd30: 0a 58 add r8, r10 ; R10=ix+220
cd32: 0b 4e mov r14, r11 ;
cd34: 0b 5f add r15, r11 ; R11 = ix+len
{
tmp = TAB_UART[ix+i];
cd36: 4f 4c mov.b r12, r15 ; len is lost !
cd38: 0e 4a mov r10, r14 ; ix is lost !
cd3a: 0e 5f add r15, r14 ;
cd3c: 6d 4e mov.b @r14, r13 ; ix is lost !
TAB_UART[ix+i] = TAB_UART[ix+len-i-1];
cd3e: 04 4b mov r11, r4 ;
cd40: 04 8f sub r15, r4 ;
cd42: 0f 44 mov r4, r15 ;
cd44: 0f 58 add r8, r15 ;
cd46: de 4f ff ff mov.b -1(r15),0(r14) ;
cd4a: 00 00
TAB_UART[ix+len-i-1] = tmp;
cd4c: cf 4d ff ff mov.b r13, -1(r15) ;
i++;
cd50: 5c 53 inc.b r12 ;
} while (i<l);
cd52: 4c 99 cmp.b r9, r12 ;
cd54: f0 2b jnc $-30 ;abs 0xcd36
}
cd56: 34 41 pop r4 ;
cd58: 38 41 pop r8 ;
cd5a: 39 41 pop r9 ;
cd5c: 3a 41 pop r10 ;
cd5e: 3b 41 pop r11 ;
cd60: 30 41 ret