<<< The OFFSET Operator and LEA Instruction | Index | Ambiguous moves: PTR directive >>> |
LEA does loading of memory offset value into a register.
Suppose we want to load EBX with the offset value of table1.
We could write
mov ebx, OFFSET table1
OFFSET operator resolves offset at the assembly time.
Another way of loading memory offset is by using the LEA instruction:
LEA resolves offset at run time:
lea ebx, [table1] ; load effective address of table1 into ebx
The format of LEA instruction is
LEA register, source
We must to use LEA when the needed offset is available at run time only.
Consider array index, passed as a parameter to a procedure in register ESI, would require
To load EBX with the address of the element of table1, where element index is in ESI,
lea ebx, [ table1 + esi ] lea ebx, [ table1 ] + esi ; does the same thing lea ebx, table1[ esi ] ; does the same thing
NOTE: We cannot use the MOV instruction to do this !
<<< The OFFSET Operator and LEA Instruction | Index | Ambiguous moves: PTR directive >>> |