为什么PUSHAD指令要存储ESP?如果我想使用POPAD恢复ESP,在使用POPAD之前我必须知道ESP的正确内容。将 ESP 存储在 PUSHAD 中似乎没有用。
任何人都可以提供一些解释吗?谢谢。
最佳答案
根据我的研究,PUSHA
指令于 1982 年在处理器中引入 Wikipedia: Intel 80286 .
文档 "Intel 80286 Programmer's Reference Manual 1987"用文字解释它的目的:
...PUSHA (Push All Registers) saves the contents of the eight general registers on the stack... This instruction simplifies procedure calls by reducing the number of instructions required to retain the contents of the general registers for use in a procedure. PUSHA is complemented by POPA...
...POPA (Pop All Registers) pops the eight general registers given in the description above, except that the SP value is discarded instead of loaded into SP. POPA reverses a previous PUSHA, restoring the general registers to their values before PUSHA was executed...
...An interrupt service routine may affect registers other than other IP, CS, and FLAGS. It is the responsibility of an interrupt routine to save additional context information before proceeding so that the state of the machine can be restored upon completion of the interrupt service routine (PUSHA and POPA instructions are intended for these operations). Finally, execution of the IRET instruction pops the old IP, CS, and FLAGS from the stack and resumes the execution of the interrupted program...
...In general, the system designer is free to use almost any interrupt vectors for any given purpose. Some of the lowest-numbered vectors, however, are reserved by Intel for dedicated functions; their use is specifically implied by certain types of exceptions. None of the first 32 vectors should be defined by the user; these vectors are either invoked by pre-defined exceptions or reserved by Intel for future expansion...
我的松散翻译是,它应该是一种在某个时间点创建处理器“状态”快照的简单方法,以便异常处理程序可以检查它并采取适当的纠正措施。检查调用者的堆栈帧是可能需要做的事情之一。
一旦做出这个设计决定,它实际上被固定并卡住到今天,因为“完全向后兼容的指令集”是 x86 架构的典型特征(参见 Wikipedia: x86 ,Wikipedia: x86-64 )
delphifirst: Why PUSHAD instruction bother to store ESP?
它做到了。时期。为什么工程师 30 年前决定......现在是毫无意义的问题,对当今程序员的编程决策没有影响
关于assembly - 为什么PUSHAD指令存储ESP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27263542/