inline assembly problem

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

inline assembly problem

ソリューションへジャンプ
2,699件の閲覧回数
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,903件の閲覧回数
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,904件の閲覧回数
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,903件の閲覧回数
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,903件の閲覧回数
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!
-----------------------------------------------------------------------------------------------------------------------