简体   繁体   English

ARM对C语句的指令

[英]ARM instructions to C statements

If I want to write a C statement equivalent to ARM assembly instructions: 如果要编写与ARM汇编指令等效的C语句:

mov r0, #2 

Do I write it as a function? 我可以将其编写为函数吗? (ie): (IE):

myfunc1 
mov r0, #2 
bx lr 

Or do I write it this way: 还是我这样写:

asm("mov r0, #2)

Writing assembly inline for C depends on compiler extensions. 为C内联编写汇编程序取决于编译器扩展。 How exactly you do it will be specific to the compiler you use. 具体如何执行将取决于您使用的编译器。

For gcc, the construct to use is 对于gcc, 要使用构造是

   asm ( assembler template 
       : output operands                  /* optional */
       : input operands                   /* optional */
       : list of clobbered registers      /* optional */
       );

So, you're right, you use asm("mov r0, #2") if you use gcc. 因此,您是对的,如果使用gcc,则使用asm("mov r0, #2")

However, you arbitrarily used r0 and you don't tell your compiler that so your assembly code will conflict with the compiler's. 但是,您任意使用r0并且没有告诉编译器这样的汇编代码将与编译器的冲突。 You need to add r0 to the clobber list so you compiler can save the register before calling your code if needed. 您需要将r0添加到clobber列表,以便编译器可以在需要时在调用代码之前保存寄存器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM