为什么mov指令不能取局部变量的地址?
我在看一本叫《PC Assembly Language》的汇编教程,对其中一段不明白,希望有人给个解释,
原文如下:
"
Consider the case of passing the address of a variable (let’s call it x) to a function
(let’s call it foo). If x is located at EBP − 8 on the stack, one cannot just use:
mov eax, ebp - 8
Why? The value that MOV stores into EAX must be computed by the assembler
(that is, it must in the end be a constant).However, there is an instruction that does the desired calculation.
It is called LEA (for Load Effective Address).
The following would calculate the address of x and store it into EAX:
lea eax, [ebp - 8]
"
作者说“MOV到EAX的数据必须由Assembler(汇编器)计算,MOV指令的第二个操作数必须是一个常量”
这点我不是很清楚。
看到有人说,将它改为:
mov eax, ebp
sub eax, 8
执行结果和lea指令相同,只是效率低,是这样吗?