tags:

views:

80

answers:

1
ar db "Defference $"

What the difference when I used

mov dl,offset ar

and

lea dl,ar

I think both are doing same work but what is the difference between these two

Please specify clearly

+1  A: 

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.

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

With lea you can do it with just one instruction:

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.

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.

Nils Pipenbrinck
Also `offset ar` - is immediate value which is calculated during translation. And `lea` - is actual processor instruction "Load Effective Address" with second operand which references to memmory.
ony