What is the difference between MOV and LEA?

I would like to know what the difference between these instructions is:

MOV AX, [TABLE-ADDR]

and

LEA AX, [TABLE-ADDR]

  • LEA means Load Effective Address
  • MOV means Load Value
  • In short, LEA loads a pointer to the item you're addressing whereas MOV loads the actual value at that address.

    The purpose of LEA is to allow one to perform a non-trivial address calculation and store the result [for later usage]

    LEA ax, [BP+SI+5] ; Compute address of value
    
    MOV ax, [BP+SI+5] ; Load value at that address
    

    Where there are just constants involved, MOV (through the assembler's constant calculations) can sometimes appear to overlap with the simplest cases of usage of LEA . Its useful if you have a multi-part calculation with multiple base addresses etc.


    In NASM syntax:

    mov eax, var       == lea eax, [var]   ; i.e. mov r32, imm32
    lea eax, [var+16]  == mov eax, var+16
    lea eax, [eax*4]   == shl eax, 2        ; but without setting flags
    

    In MASM syntax, use OFFSET var to get a mov-immediate instead of a load.


    The instruction MOV reg,addr means read a variable stored at address addr into register reg. The instruction LEA reg,addr means read the address (not the variable stored at the address) into register reg.

    Another form of the MOV instruction is MOV reg,immdata which means read the immediate data (ie constant) immdata into register reg. Note that if the addr in LEA reg,addr is just a constant (ie a fixed offset) then that LEA instruction is essentially exactly the same as an equivalent MOV reg,immdata instruction that loads the same constant as immediate data.

    链接地址: http://www.djcxy.com/p/72408.html

    上一篇: x86汇编指令优化

    下一篇: MOV和LEA有什么区别?