gpt4 book ai didi

ios - "Invalid operand for instruction"arm64 架构错误

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

尝试在 arm64 架构中运行以下内联汇编指令时出现编译错误。在 32 位架构下运行良好。

Store指令将堆栈指针(sp)存储到变量stack_ptr。

unsigned long stack_ptr = 0;

__asm__ __volatile__("str sp, %[stack_ptr]"
:[stack_ptr]"=m" (stack_ptr) //output operand list
);

最佳答案

在 64 位代码中,您不能使用 SP 作为 STR 指令中的操作数。引用 documentation :

You can only use SP as an operand in the following instructions:

  • As the base register for loads and stores. In this case it must be quadword-aligned before adding any offset, or a stack alignment exception occurs.
  • As a source or destination for arithmetic instructions, but it cannot be used as the destination in instructions that set the condition flags.
  • In logical instructions, for example in order to align it.

你应该先将它复制到一个通用寄存器中,然后将它存储到内存中。

除非你需要一个真正精确的值,否则你可以只使用普通 C 并获取局部变量本身的地址来估计堆栈指针:

unsigned long stack_ptr = (unsigned long)&stack_ptr;

关于ios - "Invalid operand for instruction"arm64 架构错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31915667/

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