汇编代码中的地址和“lea" [英] Addresses in assembly code and "lea"

查看:38
本文介绍了汇编代码中的地址和“lea"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我说:

lea (%eax,%eax,2), %edx

有人告诉我,这基本上意味着:

I've been taught that it essentially means:

edx = eax + eax * 2

这个格式是如何工作的?

How does the format to this work?

我想这会引出第二个问题.如果我有这样的事情:

And I guess this leads into the second question. If I have something like this:

add -0x4(%esi, %ebx, 4), %eax

我知道第一个操作数被添加到第二个操作数,然后存储在第二个操作数中,但同样,我不明白的是第一个操作数的符号.另一个例子是如果我有:

I understand that the first operand is added to the second operand and then stored in the second operand, but again, what I don't understand is the first operand's notation. Another example would be if I had:

cmp %eax, (%esi, %ebx, 4)

...,这是否意味着正在将 %eax 处的值与以下值进行比较:

..., does this mean that the value at %eax is being compared with the value of:

esi + ebx * 4

...?我尝试搜索了很多这样的东西,但我想我没有使用正确的词来找到有意义的答案,所以我决定在这里发帖.

...? I tried searching a lot of this stuff but I guess I wasn't using the correct words to find a meaningful answer so I decided to post here.

推荐答案

Calculating values with lea 让人想起这个操作要么更快(因为它是由执行地址计算的电路计算的)要么代码量更小.请注意,只需一个操作,您就可以一步完成加法和乘法.当前的处理器可能会更快地执行此操作,而不是 add 后跟 mul,但鉴于推测执行、算术单元复制等,尚不清楚.

Calculating values with lea is a reminiscent where this operation was either faster (as it was calculated by the circuitry doing address calculation) or smaller in code size. Note that with just one operation you're able to do an add and a multiplication in just one step. Current processors may be faster in doing it instead an add followed by a mul, but it is not clear given speculative execution, arithmetic unit replication, etc.

至于以下说明,只要您看到括号就表示您正在取消引用该地址,因此:

As for the following instructions, whenever you see the parentheses mean you're dereferencing that address, so:

add -0x4(%esi, %ebx, 4), %eax

意味着放入%eax它在-4 + esi + ebx*4给出的地址中的内容,因此它意味着访问内存中的该位置并分配%eax 中存储的内容.

means put in %eax what it is in the address given by -4 + esi + ebx*4, so it implies accessing to that position in memory and assigning what's stored there to %eax.

这篇关于汇编代码中的地址和“lea"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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