推送一个寄存器会清空那个寄存器吗? [英] Does pushing a register empty that register?

查看:28
本文介绍了推送一个寄存器会清空那个寄存器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多有关这方面的书籍和说明,但是从未指定的一件事是,在将寄存器压入堆栈后会发生什么.例如,如果您在汇编中编写push ECX",ECX 寄存器的内容将被压入堆栈(显然).我不知道的是,一旦你这样做了,ECX 寄存器是保留它在推送之前包含的值,还是在推送之后它自己清空?

I have read many books and instructions on this, but one thing that is never specified is what happens to a register after you push it on the stack. For example if you write in assembly "push ECX", the contents of the ECX register will be pushed on the stack (obviously). What I don't know is, once you did this, does the ECX register keep the value it contained before the push, or did it empty itself after the push?

推荐答案

CPU 几乎总是 copy,而不是 copy + zero-the-src.尽管像 mov 这样的指令助记符表示移动",但实际操作是复制"(在寄存器之间),或者从内存加载或存储.

CPUs almost always copy, not copy + zero-the-src. Despite instruction mnemonics like mov for "move", the actual operation is "copy" (between registers), or load or store from/to memory.

寄存器不能为空",它总是有一些值.(传统的 x87 FP 堆栈寄存器除外;有一个单独的状态寄存器用于跟踪哪些 x87 寄存器为空/有值).

A register can't be "empty", it always has some value. (Except the legacy x87 FP stack registers; there is a separate status register that tracks which x87 registers being empty / having a value).

如果指令破坏了它的源操作数,文档中总是会注明.就像在高级编程语言中一样,读取变量不会修改它,除非发生了非常奇怪的事情.

If an instruction destroys its source operand, that's always noted in the documentation. Just like in high-level programming languages where reading a variable doesn't modify it unless something super weird is happening.

您可以通过使用具有 2 个不同寄存器值的 push 轻松尝试并自己找到答案.在您的调试器中单步执行它并注意寄存器值没有改变(只有 ESP 和内存发生了变化).

You can easily try this and find the answer yourself by using push with 2 different register values. Single-step it in your debugger and notice that the register values don't change (only ESP changes, and memory).

您还可以查看 ISA 参考手册(HTML 摘录)https://www.felixcloutier.com/x86/push .ZE Nir ​​引用了其中的操作"部分.

Also you can look at (an HTML extract of) the ISA reference manual, https://www.felixcloutier.com/x86/push .Z E Nir quoted the "Operation" section from it.

这篇关于推送一个寄存器会清空那个寄存器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆