为什么mov指令不能取局部变量的地址?

swimmer2000 2015-10-22 05:37:46
我在看一本叫《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指令相同,只是效率低,是这样吗?
...全文
211 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zara 2015-10-23
  • 打赏
  • 举报
回复
引用
执行结果和lea指令相同,只是效率低,是这样吗?
大致是的,只是 lea 不影响标记位,而你这个会影响到。
其实,这个解释有些简单事儿复杂化了,也就只是 MOV 指令没有运算功能,所以源操作数必须的直接的、确定的。

21,459

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧