推动寄存器清空该寄存器吗? [英] Does pushing a register empty that register?

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

问题描述

我已经阅读了许多书籍和说明,但是从未指定的一件事是将寄存器压入堆栈后会发生什么.例如,如果您在程序集"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 + the-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.

您可以轻松地尝试此操作,并通过将push与2个不同的寄存器值一起使用来自己找到答案.在调试器中单步执行它,然后注意寄存器值不会更改(只有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天全站免登陆