为什么 MIPS 堆栈指针需要保持双字对齐?

Why does the MIPS stack pointer need to be kept double word aligned?

我在几个地方读过这篇文章,但没有完全理解为什么。我明白为什么在 MIPS32 中所有指令都必须按 4 字节字对齐。

但后来我读到堆栈帧需要是8的倍数,因为堆栈指针需要双字对齐。为什么?

我理解附图中的所有内容,除了添加空 space 以将堆栈填充为 8 字节的倍数的原因。

编辑:我阅读这篇文章的来源之一是 here,第 3 页,项目符号 4。另一个来源是 Patterson 和 Hennessey 的《计算机组织与设计》第 5 版,附录 A.6,在过程调用示例。但是,现在我很清楚我误以为他们在谈论 MIPS32。

MIPS 架构只能访问内存中与其大小均匀对齐的数据类型。

参见 Dominic Sweetman 的 MIPS 运行 在第 320 页上说:

At the point where a subroutine is called, sp must be eight-byte-aligned, matching the alignment of the largest basic types - a long long integer, or a floating-point double. The eight-byte alignment is not required by 32-bit MIPS integer hardware, but it is essential for compatibility...

因此,如果您从不尝试将 double 压入堆栈,您可以很好地适应 32 位系统上的 4 字节对齐。不过,您的 OS 是否可以,这是另一个问题。