Valhalla Legends Archive

Programming => General Programming => Assembly Language (any cpu) => Topic started by: Maddox on February 24, 2004, 08:15 PM

Title: lea vs mov
Post by: Maddox on February 24, 2004, 08:15 PM
Basically, I just want to know the difference.
Title: Re:lea vs mov
Post by: K on February 24, 2004, 08:59 PM
This reference always helps me:

http://202.114.22.131/mirrors/www_litespeed_org/Tutorials/Drme2.htm

QuoteLEA means Load Effective Address.

Syntax:
LEA destination,source

Desination can be any 16 bit register and the source must be a memory operand (bit of data in memory). It puts the offset address of the source in the destination.

MOV is pretty self explanatory.
Title: Re:lea vs mov
Post by: Maddox on February 25, 2004, 12:09 AM
Quote from: K on February 24, 2004, 08:59 PM
This reference always helps me:

http://202.114.22.131/mirrors/www_litespeed_org/Tutorials/Drme2.htm

QuoteLEA means Load Effective Address.

Syntax:
LEA destination,source

Desination can be any 16 bit register and the source must be a memory operand (bit of data in memory). It puts the offset address of the source in the destination.

MOV is pretty self explanatory.

My question really was mean to be "how does lea relate to mov?" which was indicated by the "vs." Thanks for the reference, although I wish it was in alphabetical order.

Have you ever seen LEA AX,[SI]+7 before? I'm pretty sure this is the same thing as lea ax, [si+7].

And isn't that the same as
mov ax, si
add ax, 7

It looks like lea is just there to make the code smaller by taking out all the additional arithmetic instructions to the address that would be required with mov.
Title: Re:lea vs mov
Post by: Adron on February 25, 2004, 05:05 AM
Yes, LEA is there to let you use the address calculation units to calculate something and store the result in a register. It was probably originally intended for calculating things like [BX + SI + 47], but since you can now address with any register, it has turned into a generic quick expression evaluator instruction. You can do addition of up to two registers, and a constant. You can also scale one of the registers with a small value.