问题描述
GCC为我提供了一些汇编代码,并在其中添加了以下语句:
GCC made me some assembly code, and inside theres this statement:
lea eax, [ebx+eax]
(英特尔语法)只是好奇,两者之间有什么区别?
(Intel Syntax)Just curious, what would the difference between that, and:
add eax, ebx
是吗?
eax和ebx包含函数的返回值:)
eax, and ebx contains return values from functions :)
mov eax, DWORD PTR [ebp+8]
mov DWORD PTR [esp], eax
call CALC1
mov ebx, eax.
mov eax, DWORD PTR [ebp+8]
mov DWORD PTR [esp], eax
call CALC2
lea eax, [ebx+eax]
推荐答案
您可以将结果放入EAX以外的其他寄存器中,例如lea edx, eax + ebx
. add
无法做到.
You can put the result into another register than EAX, such as lea edx, eax + ebx
. add
cannot do it.
lea
也可以有一个附加的第三操作数,例如lea eax, ebp + esi + 12
,这使它成为add
指令的替代品.
lea
can also have an additional third operand such as lea eax, ebp + esi + 12
which makes it a handier alternative to add
instruction.
您还可以将某些(单词大小的)乘法运算与之结合使用,例如lea eax, ebp + eax * 8
.
You can also combine certain (word-sized) multiplication operations with it, such as lea eax, ebp + eax * 8
.
更不用说它更好地描述了意图:)
Not to mention that it describes the intent better :)
这篇关于"lea eax,[ebx + eax]"和"lea eax,[ebx + eax]"之间的区别是什么?和“添加eax,ebx"在x86-32组装中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!