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

标签 ios assembly arm64

尝试在 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/

相关文章:

ios - 如何使 Xcode 8.2.1 刷新配置文件列表?看起来像 Xcode 错误

ios - 如何为 carbonTabSwipeNavigation CarbonKit Cocoapods 设置颜色渐变

assembly - 以问号开头的标识符的 MASM 命名约定?

memory-management - 了解 64 位 Linux 上的 kmap

linux - 如何强制页面在下次访问时生成页面错误?

ios - UIScrollView 中的 UIWebView,如 Apple Mail.app

ios - 当字符长度发生变化时,让 UILabel 在 UIView 中居中。 iOS, Objective-C

c++ - Visual Studio 2015 C++ 和程序集未构建

assembly - 具有只写目标并在英特尔的任何端口上运行的 x86 非 mov 指令?

c++ - 基于ARM的系统中浮点到整数的转换