LEA EAX [EAX] 有什么意义?

发布于 2024-08-30 02:36:02 字数 110 浏览 2 评论 0原文

LEA EAX, [EAX]

我在使用 Microsoft C 编译器编译的二进制文件中遇到了这条指令。它显然不能改变EAX的值。那么它为什么会在那里呢?

LEA EAX, [EAX]

I encountered this instruction in a binary compiled with the Microsoft C compiler. It clearly can't change the value of EAX. Then why is it there?

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

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

发布评论

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

评论(3

季末如歌 2024-09-06 02:36:02

这是一个NOP

以下内容通常用作NOP。它们都做同样的事情,但会产生不同长度的机器代码。根据对齐要求选择其中之一:

xchg eax, eax         = 90
mov eax, eax          = 89 C0 
lea eax, [eax + 0x00] = 8D 40 00 

It is a NOP.

The following are typcially used as NOP. They all do the same thing but they result in machine code of different length. Depending on the alignment requirement one of them is chosen:

xchg eax, eax         = 90
mov eax, eax          = 89 C0 
lea eax, [eax + 0x00] = 8D 40 00 
您的好友蓝忘机已上羡 2024-09-06 02:36:02

来自这篇文章:

这个技巧是由MSVC++编译器使用的
发出 NOP 指令
不同的长度(用于之前的填充
跳跃目标)。例如,MSVC++
如果是则生成以下代码
需要 4 字节和 6 字节填充:

8d6424 00 lea [ebx+00],ebx
; 4 字节填充 8d9b 00000000
lea [esp+00000000],esp ; 6字节
填充

第一行标记为“npad 4”
在生成的程序集列表中
编译器,第二个是“npad 6”。
可以选择寄存器(ebx、esp)
从很少使用的避免
代码中存在错误的依赖关系。

所以这只是一种 NOP,出现在 jmp 指令的目标之前,以便对齐它们。

有趣的是,您可以根据此类指令的特征来识别编译器。

From this article:

This trick is used by MSVC++ compiler
to emit the NOP instructions of
different length (for padding before
jump targets). For example, MSVC++
generates the following code if it
needs 4-byte and 6-byte padding:

8d6424 00 lea [ebx+00],ebx
; 4-byte padding 8d9b 00000000
lea [esp+00000000],esp ; 6-byte
padding

The first line is marked as "npad 4"
in assembly listings generated by the
compiler, and the second is "npad 6".
The registers (ebx, esp) can be chosen
from the rarely used ones to avoid
false dependencies in the code.

So this is just a kind of NOP, appearing right before targets of jmp instructions in order to align them.

Interestingly, you can identify the compiler from the characteristic nature of such instructions.

凶凌 2024-09-06 02:36:02
LEA EAX, [EAX]

事实上并没有改变EAX的值。据我了解,它的功能与以下内容相同:

MOV EAX, EAX

您在优化代码还是未优化代码中看到它?

LEA EAX, [EAX]

Indeed doesn't change the value of EAX. As far as I understand, it's identical in function to:

MOV EAX, EAX

Did you see it in optimized code, or unoptimized code?

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