c++ - LDSET ARM 指令作为内联汇编

标签 c++ assembly inline-assembly

我正在尝试使用 Atomic LDSET ARM 指令 ( http://www.keil.com/support/man/docs/armclang_asm/armclang_asm_chi1476202820379.htm ) 作为 C 中的内联汇编代码,但不知何故我无法找出正确的操作数。 这是我写的

int value = 1024; //operate on this value
int setBit = 7; //set the 7th bit
int initValue = 0; //return the original value in this
asm("ldset %w0, %w2, %x1" : "+r"(value), "=r"(initValue) : "r"(setBit));

得到这个错误:

test-lib.cpp:26:9: error: invalid operand for instruction
  asm("ldset %w0, %w2, %x1" : "+r"(value), "=r"(initValue) : "r"(setBit));
      ^
<inline asm>:1:17: note: instantiated into assembly here
      ldset w9, w10, x10
                     ^

请在这方面需要一些帮助。

最佳答案

根据 page you linked ,第三个操作数必须是一个内存引用,并且只使用一个没有偏移量的寄存器。 Q constraint is for specifically this purpose ,所以尝试:

asm("ldset %w0, %w2, %1" : "+r"(value), "=Q"(initValue) : "r"(setBit));

这应该生成类似于 ldset w0, w1, [x2] 的内容。

关于c++ - LDSET ARM 指令作为内联汇编,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47472485/

相关文章:

linux - 当用户提供文件名时无法读取文件(使用 nasm 的 x86 汇编程序)

c++ - 使用 Assembly 和 C++ 调用一个函数两次

c++ - 格式化 C++ setw

c++ - 从 Matlab 连接到本地服务器

C++ A星实现--判断节点是否已经在未清项优先队列中

调试 assembly

assembly - 玩具编译器的输出语言/格式

linux - ARM 内联汇编 : exit system call with value read from memory

c - 为什么我的程序在 Ubuntu gcc 上运行而不是 OSX gcc?

c++ - 使用 unordered_map 时编译时错误