在“mov (%eax), eax"中将寄存器移动到自身的目的是什么? [英] What is the purpose of moving a register to itself as in "mov (%eax), eax"?

查看:52
本文介绍了在“mov (%eax), eax"中将寄存器移动到自身的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 GCC 反汇编简单的 C 代码时,我遇到了:

While disassembling simple C code with GCC I came across:

mov (%eax), eax

我对汇编的理解是,当你有 () 包围一个寄存器时,你是在向内存地址添加一些数字,即 0x4(%eax)表示寄存器 %eax 上方 4 个字节.

My understanding of assembly is that when you have () surrounding a register, you are adding some number to the memory address, i.e., 0x4(%eax) would mean 4 bytes above the register %eax.

然而,这里 () 之前没有数字,因此它似乎将寄存器中的值复制到自身.

Here, however, there is no number before the (), so it appears to be copying the value in the register to itself.

我注意到 %eax 寄存器非常常用来返回变量,并且这一行在函数调用后立即出现,所以我猜测这条指令实际上是在告诉机器采取任何行动被调用函数(即返回值)的%eax寄存器,当前函数的%eax寄存器.

I have noticed that the %eax register is used quite commonly to return variables and this line occurs immediately after a function call, so my guess is that this instruction is actually telling the machine to take whatever was in the %eax register for the called function (i.e., the return value) and put in the %eax register for the current function.

这是正确的吗?如果没有,我做错了什么,它实际上在做什么?

Is this correct? If not, what have I got wrong, and what is it actually doing?

推荐答案

() 在 at&t 语法中表示内存取消引用,您可能应该阅读有效地址语法.等效的 C 代码将是 eax=*eax; 意思是,使用 eax 的当前值作为地址从内存中加载 4 个字节,并覆盖 eax 与获取的值.

() in at&t syntax denotes memory dereferencing, you should probably read about the effective address syntax. The equivalent C code would be eax=*eax; meaning, load the 4 bytes from memory using the current value of eax as address, and overwrite eax with the fetched value.

函数调用和返回不影响寄存器的值(当然堆栈和指令指针除外),没有调用者或被调用者的eax概念.

Function calls and returns do not affect the values of registers (except stack and instruction pointer of course), there is no notion of eax of the caller or the callee.

PS:如果您对 at&t 不满意,您可以使用 set disassembly-flavor intelgdb 切换到 intel 语法模式.

PS: you can switch gdb into intel syntax mode using set disassembly-flavor intel, if you are not happy with at&t.

这篇关于在“mov (%eax), eax"中将寄存器移动到自身的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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