在查看调用约定时,我注意到(特别是 ARM,但也包括 x86 System V)许多/大多数指定了两个返回寄存器。 由于 C 及其派生语言只能直接返回一个值,而某些可以返回更多值的假设语言可以返回任意数量的值:为什么这些规范中专门有两个值? (即是否有一种特定语言恰好使用两个返回值?)
最佳答案
这是来自 Procedure Call Standard for the Arm Architecture Release 2019Q1.1 的引文,第 19 页
Handling values larger than 32 bits Fundamental types larger than 32 bits may be passed as parameters to, or returned as the result of, function calls. When these types are in core registers the following rules apply:
• A double-word sized type is passed in two consecutive registers (e.g., r0 and r1, or r2 and r3). The content of the registers is as if the value had been loaded from memory representation with a single LDM instruction.
• A 128-bit containerized vector is passed in four consecutive registers. The content of the registers is as if the value had been loaded from memory with a single LDM instruction.
因此,ABI 中定义的 4 个返回寄存器 r0
-r3
用于为不适合的 C 类型返回一个单个值一个寄存器。
关于c - 为什么有两个返回寄存器(在许多过程调用约定/ABI 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59272877/