inline assembly problem

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

inline assembly problem

跳至解决方案
2,678 次查看
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

标记 (1)
0 项奖励
回复
1 解答
1,882 次查看
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 项奖励
回复
3 回复数
1,883 次查看
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 项奖励
回复
1,882 次查看
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 项奖励
回复
1,882 次查看
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!
-----------------------------------------------------------------------------------------------------------------------