inline assembly problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

inline assembly problem

Jump to solution
1,523 Views
GudeADS
Contributor III

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

Tags (1)
0 Kudos
1 Solution
727 Views
yasuhikokoumoto
Senior Contributor I

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.

View solution in original post

0 Kudos
3 Replies
728 Views
yasuhikokoumoto
Senior Contributor I

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.

0 Kudos
727 Views
GudeADS
Contributor III

I will test it, when I am back at the office on Friday. Many thanks, that will help a lot!

Best Regards

0 Kudos
727 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

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!
-----------------------------------------------------------------------------------------------------------------------