[英]operand must be an int register in armv8
I'm working on a program in ARMv8, and when attempting to compile it using gcc, I get the error message "operand 3 must be an integer register" for the following lines of code:我正在 ARMv8 中开发一个程序,当尝试使用 gcc 编译它时,我收到以下代码行的错误消息“操作数 3 必须是 integer 寄存器”:
67 mul x2, x2, 8
100 mul x16, x11, 4
117 mul x16, x11, 4
140 mul x16, x12, 4
Similarly, I get the error message "integer register expected in the extended/shifted operand register at operand 3"同样,我收到错误消息“操作数 3 的扩展/移位操作数寄存器中预期有整数寄存器”
66 add x2, xzr, #MAX_DIGITS
142 add x17, xzr, 1
What does this mean?这是什么意思? How can I fix it?我该如何解决?
AArch64 mul
doesn't have a form that takes an immediate operand, check the manual . AArch64 mul
没有采用立即操作数的形式,请查看手册。
See https://godbolt.org/z/79oKc6fxq for what compilers do: shift instead of mul for a power of 2, otherwise mov-immediate to a register before mul reg,reg,reg
.请参阅https://godbolt.org/z/79oKc6fxq了解编译器的作用:shift 而不是 mul 以获得 2 的幂,否则 mov-immediate 到mul reg,reg,reg
之前的寄存器。 Or for a 2^n+1 constant like 9
, add x0, x0, x0, lsl #3
或者对于像9
这样的 2^n+1 常量, add x0, x0, x0, lsl #3
add
-immediate with xzr
is impossible, since the same syntax compilers use for adding 1 ( add reg, reg, #1
) doesn't assemble if XZR is the source register. add
-immediate with xzr
是不可能的,因为如果 XZR 是源寄存器,则编译器用于加 1 ( add reg, reg, #1
) 的相同语法不会汇编。
For some instructions, like add
-immediate, that register number is the stack pointer, not the zero register, so xzr isn't encodeable.对于某些指令,如add
-immediate,该寄存器编号是堆栈指针,而不是零寄存器,因此 xzr 不可编码。 That makes sense;这就说得通了; there are instructions that can get a small integer into a register, but adding/subtracting is something you often want on the stack pointer.有一些指令可以将一个小的 integer 放入寄存器中,但是加/减是您经常需要在堆栈指针上进行的操作。
If you want to materialize a small immediate, use mov
and let the assembler figure out which opcode to use.如果你想具体化一个小立即数,使用mov
并让汇编器找出要使用的操作码。 If you compile a function that does return 1;
如果您编译return 1;
, clang uses mov x0, #1
for the asm source. , clang 使用mov x0, #1
作为 asm 源代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.