while not specifically answering your question,
i've used a busy loop also, and have now changed my code to
use a subroutine instead of inline busy loops.  It takes up less space.
But I discovered a bug in this, the "naked" caused the stack setup to
be eliminated on entry, but it still saved the first arg value
to the stack, which clobbered the first arg of the CALLER.
I changed it to no declare an arg, and use r15 directly, and this
now works and does not cause unexplained bugs..
and is only the 3 instructions.

-Kelly Murray


//__attribute__ ((naked)) void delayloop(unsigned int n) {
__attribute__ ((naked)) void delayloop() {
    //first arg comes in register R15
    //the loop uses 3 cycles per round
    //the eight cycles come from the call overhead and ret
    //
    //delay_time = (1/MCLK)*(8+(3*n))
  // asm("spinloop: dec %0\n  jnz spinloop" :: "r" (n));  return;
  asm("spinloop: dec r15\n  jnz spinloop\n ret");

}

...  delayloop(init);
  // i = init; asm("wloop1: dec %0\n  jnz wloop1\n" :: "r" (i));




Matthias Weingart wrote:
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.


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users





Reply via email to