IA-32的常见调用规约如下所示:
• Callee-save registers
%ebx, %esi, %edi, %ebp, %esp
Callee must not change these. (Or restore the caller's values before returning.)
• Caller-save registers
%eax, %edx, %ecx, condition flags
Caller saves these if it wants to preserve them. Callee can freely clobber.
为什么存在这种奇怪的惯例?为什么不在调用另一个函数之前保存所有寄存器?或者让被调用者使用 pusha
/popa
来保存和恢复所有内容呢?