LDSET ARM 指令作为内联汇编
LDSET ARM instruction as 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, the third operand must be a memory reference, and one which uses just a single register without an offset. The Q
constraint is for specifically this purpose,所以尝试:
asm("ldset %w0, %w2, %1" : "+r"(value), "=Q"(initValue) : "r"(setBit));
这应该生成类似 ldset w0, w1, [x2]
的内容。
我正在尝试使用 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, the third operand must be a memory reference, and one which uses just a single register without an offset. The Q
constraint is for specifically this purpose,所以尝试:
asm("ldset %w0, %w2, %1" : "+r"(value), "=Q"(initValue) : "r"(setBit));
这应该生成类似 ldset w0, w1, [x2]
的内容。