gpt4 book ai didi

c - : :"r" vs :"=r" assembly clarification

转载 作者:行者123 更新时间:2023-12-02 04:11:25 25 4
gpt4 key购买 nike

我正在尝试理解用汇编编写的语法,以便首先正确地编写代码,其次才能高效地编写代码。在此示例中,它显示了使用 "=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 平台上。谢谢。

最佳答案

在书中找到答案:Professional Assembly Language: Extended ASM

If no output values are associated with the assembly code, the sectionmust be blank, but two colons must still separate the assembly codefrom the input operands.

原因是因为这是标准。一个冒号表示输出,两个冒号表示输入。

关于c - : :"r" vs :"=r" assembly clarification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36560646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com