Page 1 of 1

What do LDS, LES, etc do?

Posted: Fri Mar 09, 2007 9:37 pm
by Alboin
What do LDS, LES, etc. (These) do exactly? Also, how does one get the offset and segments from an address? (I'm working on some instructions for a 8\16bit x86 emulator.) Sorry if this sounds dumb, I've just never used them.

Thanks!

Posted: Fri Mar 09, 2007 10:17 pm
by ~
It would be better to read from the Intel/AMD manuals. For what says there:


Load Far Pointer

LDS
LES
LFS
LGS
LSS


Loads a far pointer from a memory location (second operand):

lds ax,[myFARLabel_16_XX]

into a segment register (mnemonic):

LDS = DS
LES = ES
LFS = FS
LGS = GS
LSS = SS

and general purpose register (first operand):

lds ax,[myFARLabel_16_XX]


The instruction stores the 16-bit segment selector of the pointer into the segment register and the 16-bit or 32-bit offset portion into the general-purpose register. The operand size attribute determines whether the pointer is 32-bit (mem16:16 -- it is, 1 word for segment register and 1 word for offset in AX,BX,CX or DX) or 48-bit (mem16:32 -- it is, 1 word for segment register and 1 dword for EAX,EBX,ECX or EDX).

These instructions load associated segment descriptor information into the hidden portion of the specified segment register.

Using LDS or LES in 64-bit mode generates an invalid-opcode exception.

Executing LFS, LGS, or LSS with a 64-bit operand size only loads a 32-bit general purpose register and the specified segment register.

Possible combinations (NASM syntax):

lds ax,[myFARLabel_16_16]
lds bx,[myFARLabel_16_16]
lds cx,[myFARLabel_16_16]
lds dx,[myFARLabel_16_16]
------------
lds eax,[myFARLabel_16_32]
lds ebx,[myFARLabel_16_32]
lds ecx,[myFARLabel_16_32]
lds edx,[myFARLabel_16_32]
------------
les ax,[myFARLabel_16_16]
les bx,[myFARLabel_16_16]
les cx,[myFARLabel_16_16]
les dx,[myFARLabel_16_16]
------------
les eax,[myFARLabel_16_32]
les ebx,[myFARLabel_16_32]
les ecx,[myFARLabel_16_32]
les edx,[myFARLabel_16_32]
------------
lfs ax,[myFARLabel_16_16]
lfs bx,[myFARLabel_16_16]
lfs cx,[myFARLabel_16_16]
lfs dx,[myFARLabel_16_16]
------------
lfs eax,[myFARLabel_16_32]
lfs ebx,[myFARLabel_16_32]
lfs ecx,[myFARLabel_16_32]
lfs edx,[myFARLabel_16_32]
------------
lgs ax,[myFARLabel_16_16]
lgs bx,[myFARLabel_16_16]
lgs cx,[myFARLabel_16_16]
lgs dx,[myFARLabel_16_16]
------------
lgs eax,[myFARLabel_16_32]
lgs ebx,[myFARLabel_16_32]
lgs ecx,[myFARLabel_16_32]
lgs edx,[myFARLabel_16_32]
------------
lss ax,[myFARLabel_16_16]
lss bx,[myFARLabel_16_16]
lss cx,[myFARLabel_16_16]
lss dx,[myFARLabel_16_16]
------------
lss eax,[myFARLabel_16_32]
lss ebx,[myFARLabel_16_32]
lss ecx,[myFARLabel_16_32]
lss edx,[myFARLabel_16_32]
------------


We can say that the following:

Code: Select all

   lds eax,[myFARLabel_16_32]

Is the same than:

Code: Select all

   mov eax,[storedSegmentOffset]

   push eax
   mov ax,[storedDS]
   mov ds,ax
   pop eax
That's why it's called "Load Far Pointer", it's a specific segment and its offset.

Posted: Fri Mar 09, 2007 11:46 pm
by earlz
....
so that explains it...

should be quite simple [inside thingy]