On Tue, 10 May 2005 at 11:39 +0200, thln  wrote:

So, if i write the following function (Swap_TAB_UART), the result is not
good.  the function loses len, ix values.

It seems that the C compiler overwrites registers !!!

You probably already realized this, but at the point
where you thought that len and ix were lost, that
the compiler has pre-computed  temporary values based
on those values, so len and ix are not really used any
more.

void Swap_TAB_UART(unsigned char ix, unsigned char len)
{
unsigned char i, tmp, l;

l = len/2;
i = 0;

 at this point the compiler calculates ix+len
 and stores it in R11, so len itself is not used

 also R11 gets &TAB_UART[ix], and since ix doesn't change
 the compiler realized that it can through away ix

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);
}

Reply via email to