What is the difference between the following commands: LEA
, LDS
, LES
? I searched for the answer but I'm not very clear on it. From what I understood block1
should be equivalent to block2
.
.data
str1 db 'My first string. $'
str2 db 'My second string. $'
ptr_str1 dd str1
ptr_str2 dd str2
.code
_block1:
mov AX, @data
mov DS, AX
mov ES, AX
lea SI, str1
lea DI, str2
_block2:
lds SI, ptr_str1
les DI, ptr_str2
... but when I print str1
and str1
using the following macro, the second block doesn't return the expected results.
print MACRO param
lea DX, param
mov AH, 9
int 21h
ENDM
The lea instruction places the address specified by its first operand into the register specified by its second operand. Note, the contents of the memory location are not loaded, only the effective address is computed and placed into the register.
lds means Load pointer using DS and likewise les means Load pointer using ES.
Purpose. Load a doubleword of data into the specified general purpose register.
The LEA (Load Effective Address) instruction is a way of obtaining the address which arises from any of the Intel processor's memory addressing modes. it moves the contents of the designated memory location into the target register.
lea
means Load Effective Address. So lea SI, str1
sets si
to the offset of str1
. The correct memory addressing syntax used by lea
and other instructions depends on the assembler used, some assemblers want lea si,[str1]
.
lds
and les
do something completely different compared to lea
. lds
means Load pointer using DS and likewise les
means Load pointer using ES. In practice, lds SI, ptr_str1
sets ds
and si
based on the values stored in the memory address ds:ptr_str1
(the syntax is [ds:ptr_str1]
in some assemblers).
So, what these instructions do in your code:
lea SI, str1
sets si
to point to the address of str1
. This seems perfectly OK.
lds SI, ptr_str1
sets si
to 'My'
(0x794d in hexadecimal) and also sets ds
to ' f'
(0x6620 in hexadecimal). Note that x86 is a little-endian architecture. ds
is the default segment from where the pointer value is read using lds
and les
. So instead of loading the string address to ds:si
, the first 4 bytes of the string are used as an address that is loaded into ds:si
. I assume this is not what you wanted to do.
les DI, ptr_str2
sets di
according to the value stored in 0x6620:ptr_str2 (ds
is the default segment for most x86 instructions, and currently ds
has the value 0x6620) and also sets es
according to the value stored in 0x6620:ptr_str2+2. Probably this is not what you wanted to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With