Pushfd 和 Pushad:有什么意义?

发布于 2025-01-06 09:38:46 字数 164 浏览 2 评论 0原文

我知道 Pushad 将所有 32 位寄存器压入堆栈,但最终存储在堆栈上的唯一寄存器是 EDI。标志值不受影响,那么使用 Pushad 有什么意义呢?此外,我知道 Pushfd 以双精度格式推送所有标志值。那么,如果标志值通常只有 0 或 1,pushfd 操作如何将诸如 00000A46 之类的值推送到堆栈呢?

I know that pushad pushes all the 32 bit registers onto the stack, but the only register that ends up being stored on the stack is EDI. Flag values aren't affected so what's the point of using pushad? Additionally, I know that pushfd pushes all flag values in a double format. So, if flag values are usually only 0 or 1 how does the pushfd operation push a value such as 00000A46 to the stack?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱殇璃 2025-01-13 09:38:46

...最终存储在堆栈上的唯一寄存器是 EDI。

不会。PUSHAD 指令总是所有 8 个通用寄存器压入堆栈。单个 PUSHAD 指令相当于写入:

Push EAX
Push ECX
Push EDX
Push EBX
Push ESP
Push EBP
Push ESI
Push EDI

POPAD 以相反的顺序将值从堆栈中弹出,从而恢复所有寄存器值。

PUSHAD 和 POPAD 对于执行通用寄存器的简单保存和恢复非常有用,而无需依次 PUSH 和 POP 每个单独的寄存器。

同样,PUSHFD和POPFD用于保存和恢复EFLAGS寄存器。尽管在普通程序中并没有真正使用那么多,但这些指令在(例如)执行进程上下文切换时(或必须恢复标志寄存器值的任何其他地方)很有用。

pushfd操作如何将00000A46这样的值压入堆栈?

这就是数据的解释方式。 EFLAGS 寄存器是一组 32 位。如果将位分为 8 组,每组 4 个 (8*4=32),则可以将每个 4 位块映射到十六进制字符 (0..9,AF)。同样,您可以将十六进制值转换回一组位:

00000A46 = 0000(0) 0000(0) 0000(0) 0000(0) 0000(0) 1010(A) 0100(4) 0110(6)

这些是存储在 EFLAGS 寄存器中的位的值。

...the only register that ends up being stored on the stack is EDI.

No. The PUSHAD instruction always pushes all 8 general purpose registers onto the stack. A single PUSHAD instruction is equivilent to writing:

Push EAX
Push ECX
Push EDX
Push EBX
Push ESP
Push EBP
Push ESI
Push EDI

POPAD pops the values back off the stack in reverse order, thus restoring all the register values.

PUSHAD and POPAD are useful for performing a easy save and restore of the general purpose registers without having to PUSH and POP every individual register in turn.

Similarly, PUSHFD and POPFD are used to save and restore the EFLAGS register. Although not really used that much in ordinary programs, the instructions are useful when (for example) a process context switch is performed (or anywhere else where the value of the flags register must be restored).

how does the pushfd operation push a value such as 00000A46 to the stack?

It's just how the data is interpreted. The EFLAGS register is a set of 32 bits. If you divide the bits up into 8 groups of 4 (8*4=32), you can map each 4 bit chunk to a hexadecimal character (0..9,A-F). Likewise, you can convert the hexadecimal values back to a set of bits:

00000A46 = 0000(0) 0000(0) 0000(0) 0000(0) 0000(0) 1010(A) 0100(4) 0110(6)

These are the values of the bits that were stored in the EFLAGS register.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文