LEA和偏移的区别 [英] Difference between lea and offset
问题描述
ar db "Defference $"
有什么
mov dx,offset ar
和
lea dx,ar
我觉得这两个都在做同样的工作,但正是这两者之间的区别
I think both are doing same work, but what is the difference between these two
推荐答案
在此用例LEA和MOV做同样的事情。如果你想在一个更复杂的方法来计算一个地址LEA比MOV更强大。
In this use-case LEA and MOV do the same thing. LEA is more powerful than MOV if you want to calculate an address in a more complex way.
让例如说,你想要得到的第n个字符的地址数组中,和n存储在BX。随着MOV,你必须编写以下两个指令:
Lets for example say you want to get the address of the n'th character in your array, and the n is stored in bx. With MOV you have to write the following two instructions:
Mov dx, offset ar
add dx, bx
使用LEA,你可以只用一个指令做到这一点:
With lea you can do it with just one instruction:
lea dx, [ar + bx]
另一个要考虑这里:在添加DX,BX
指令将改变CPU的状态标志。在 LEA DX内部完成的增加,[AR + BX],另一方面
指令,因为它不被视为一个算术指令不更改标记以任何方式。
Another thing to consider here: the add dx,bx
instruction will change the status flags of the CPU. The addition done inside the lea dx, [ar + bx]
instruction on the other hand does not change the flags in any way because it is not considered an arithmetic instruction.
如果您想preserve标志,同时做一些简单的计算,这有时是非常有用(地址的计算是很常见的)。存储和恢复的标志寄存器是可行的,但一个缓慢的操作。
This is sometimes helpful if you want to preserve the flags while doing some simple calculations (address calculations are very common). Storing and restoring the flag-register is doable but a slow operation.
这篇关于LEA和偏移的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!