Hi,
again a problem with volatile - or too much optimizing of the compiler. With
"volatile uint n;" my code will work as expected, but it uses space on the
stack and it wastes cycles. I want registers for my purpose.
This is the code (Stripped down to something useless :-)
#define VALUE 8
void foo(void)
{
{
uint n;
n=VALUE;
__asm__ __volatile__("dec %0\n jnz $-2\n" :: "r" (n));
}
//do someth.
{
uint n;
n=VALUE;
__asm__ __volatile__("dec %0\n jnz $-2\n" :: "r" (n));
}
//do someth.
}
The compiler is setting N=2*VALUE before the first loop:
mov #16, r15
dec r15
jnz $-2
... ;do smth.
dec r15
jnz $-2
... ;do smth.
ret
but I want it to look like this:
mov #8, r15
dec r15
jnz $-2
... ;do smth.
mov #8, r15
dec r15
jnz $-2
... ;do smth.
ret
any ideas?
thx
M.