我正在尝试使用 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/