Hello,
I want to code a delay loop in gcc inline assembly for a K64:
asm("push {r4}"); | |
asm("mov r4, delay_val"); | |
asm(".Lab:"); | |
asm("add r4, r4, #-1"); | |
asm("bne .Lab"); | |
asm("pop {r4}"); |
I have the push/pop instructions in here, because I have no idea how to get otherwise a free register that I can use for the small loop.
But with the push/pop instructions the exe works unstable. Any idea for a better solution?
Best Regards
Solved! Go to Solution.
Hi Andreas Schmidt,
according to IAR EWARM IDE, it would be described as following, given the loop variable was declared.
asm ("mov %0,%1" : "=r" (loop), "=r" (delay_val) : "0" (loop), "1" (delay_val));
asm ("Lab:\n\t"
"adds %0,%0,#-1\n\t"
"bne Lab\n\t" : "=r" (loop) : "0" (loop) );
As for the label, it seems not to be recognized unless it will be written in one statement by IAR. By ordinary GCC even the following statements was OK.
asm volatile ("mov %0,%1" : "=r" (loop), "=r" (delay_val) : "0" (loop), "1" (delay_val));
asm volatile (".Lab:");
asm volatile ("add %0,%0,#-1" : "=r" (loop) : "0" (loop));
asm volatile ("bne .Lab");
Best regards,
Yasuhiko Koumoto.
Hi Andreas Schmidt,
according to IAR EWARM IDE, it would be described as following, given the loop variable was declared.
asm ("mov %0,%1" : "=r" (loop), "=r" (delay_val) : "0" (loop), "1" (delay_val));
asm ("Lab:\n\t"
"adds %0,%0,#-1\n\t"
"bne Lab\n\t" : "=r" (loop) : "0" (loop) );
As for the label, it seems not to be recognized unless it will be written in one statement by IAR. By ordinary GCC even the following statements was OK.
asm volatile ("mov %0,%1" : "=r" (loop), "=r" (delay_val) : "0" (loop), "1" (delay_val));
asm volatile (".Lab:");
asm volatile ("add %0,%0,#-1" : "=r" (loop) : "0" (loop));
asm volatile ("bne .Lab");
Best regards,
Yasuhiko Koumoto.
I will test it, when I am back at the office on Friday. Many thanks, that will help a lot!
Best Regards
Hello Andreas Schmidt:
The next documents could be useful. Both are the same with some tiny differences between CW and KDS:
Extended Inline Assembly with Kinetis Design Studio
Extended inline assembly with GCC in CodeWarrior
Regards!,
Jorge Gonzalez
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------