::"r" vs :"=r" 汇编说明
::"r" vs :"=r" assembly clarification
我正在尝试理解用汇编编写的语法,以便首先正确地编写代码,其次才能高效地编写代码。
在此示例中,它显示了使用 "=r"
的示例
asm volatile ("MRS %0, PMUSERENR_EL0\n": "=r"(value));
这会读取寄存器的值并将其存储在值变量中。另一个示例使用 ::"r"
asm volatile ("MSR PMUSERENR_EL0, %0\n":: "r"(value));
这会将值变量写入 PMUSERENR_ELO 寄存器。这是它的另一个例子:How to measure program execution time in ARM Cortex-A8 processor?。
当我试图用上面的两个命令编译一个简单的测试代码时,我得到了错误::9:2: error: output operand constraint lacks '='
如果我添加“=”并删除一个“:”,它会编译,但是当我测试它时,它只是说 Illegal instruction
如果有人能解释一下有帮助的区别,许多汇编教程显示相同的格式但没有解释。如果它提供任何见解,它在 64 位 arm 平台上。谢谢。
If no output values are associated with the assembly code, the section
must be blank, but two colons must still separate the assembly code
from the input operands.
原因是因为这是标准。一个冒号表示输出,两个冒号表示输入。
我正在尝试理解用汇编编写的语法,以便首先正确地编写代码,其次才能高效地编写代码。
在此示例中,它显示了使用 "=r"
asm volatile ("MRS %0, PMUSERENR_EL0\n": "=r"(value));
这会读取寄存器的值并将其存储在值变量中。另一个示例使用 ::"r"
asm volatile ("MSR PMUSERENR_EL0, %0\n":: "r"(value));
这会将值变量写入 PMUSERENR_ELO 寄存器。这是它的另一个例子:How to measure program execution time in ARM Cortex-A8 processor?。
当我试图用上面的两个命令编译一个简单的测试代码时,我得到了错误::9:2: error: output operand constraint lacks '='
如果我添加“=”并删除一个“:”,它会编译,但是当我测试它时,它只是说 Illegal instruction
如果有人能解释一下有帮助的区别,许多汇编教程显示相同的格式但没有解释。如果它提供任何见解,它在 64 位 arm 平台上。谢谢。
If no output values are associated with the assembly code, the section must be blank, but two colons must still separate the assembly code from the input operands.
原因是因为这是标准。一个冒号表示输出,两个冒号表示输入。