c - 为什么有两个返回寄存器(在许多过程调用约定/ABI 中)

标签 c assembly arm

在查看调用约定时,我注意到(特别是 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/

相关文章:

c - 为什么 typedef 声明不称为 typedef 定义?

c - 如何使用 GCC 获取与程序集输出内联的源代码行?

c++ - 设置位是否与同一个字上的并发其他位集发生冲突?

python - 由于 "TypeError: unhashable type: ' bytearray'"(在树莓派中)导致消息被截断

c - 为什么在 C 语言中字符串长度要加一其容量?

c - 使用 sigaction 时未调用信号处理程序

c - C 中的 3 维数组在 for 循环后更改值

assembly - 使先前的内存存储对后续的内存加载可见

linux - 可以在 Windows 上的 Docker 中运行 ARM/rpi 图像,但不能在 linux 上运行

mono - 无法为 ARM 交叉编译 Mono