Page 1 of 1
x86 Processor instruction "LDS"; When this is useful?
Posted: Thu Dec 09, 2010 11:08 pm
by osdevkid
Hi all,
I know, what "LDS" processor command will do.
Code: Select all
ORG 100h
LDS AX, m
RET
m DW 1234h
DW 5678h
END
AX is set to 1234h, DS is set to 5678h.
I want to know, when we will use this command ? where it is actually required in OS development or for any other purpose.
Re: x86 Processor instruction "LDS"; When this is useful?
Posted: Fri Dec 10, 2010 2:26 am
by xenos
As you can see in your example, it loads a far pointer into DS:AX. So whenever you want to load a far pointer from memory, you can use this (or a similar) command.
Re: x86 Processor instruction "LDS"; When this is useful?
Posted: Fri Dec 10, 2010 4:25 am
by osdevkid
Thank you, I understood.
Re: x86 Processor instruction "LDS"; When this is useful?
Posted: Sun Dec 12, 2010 12:59 am
by miker00lz
its very useful when you need to load a 16-bit:16-bit segment:offset vector from some memory location. it can be done easily with other operations, but this generally saves some CPU cycles. not very useful if you just want to store the values somewhere, but rather if you want to go access data from where it points to. LES is the same, but of course, moves the segment into ES.
Re: x86 Processor instruction "LDS"; When this is useful?
Posted: Mon Dec 13, 2010 8:31 am
by qw
And LDS, LES etcetera are guaranteed not te be interrupted, which is useful when setting up a stack (with LSS).
Re: x86 Processor instruction "LDS"; When this is useful?
Posted: Mon Dec 13, 2010 3:58 pm
by bewing
I'm going to have to disagree with the tone of the previous replies. For almost all current OS or application development, segment registers are obsolete. No application should ever modify them. In a perfect world, your OS should only need to set them once, and then never touch them again. The only exception is playtime experimental rmode OSes. LDS and its cousins are somewhat extra clever opcodes for initting segment registers. Therefore, they are almost completely worthless. As implied above, you can easily perform the same functionality with a few more "regular" opcodes, and you should almost never need to init your segment registers anyway.
Re: x86 Processor instruction "LDS"; When this is useful?
Posted: Tue Dec 14, 2010 2:44 pm
by miker00lz
bewing wrote:I'm going to have to disagree with the tone of the previous replies. For almost all current OS or application development, segment registers are obsolete. No application should ever modify them. In a perfect world, your OS should only need to set them once, and then never touch them again. The only exception is playtime experimental rmode OSes. LDS and its cousins are somewhat extra clever opcodes for initting segment registers. Therefore, they are almost completely worthless. As implied above, you can easily perform the same functionality with a few more "regular" opcodes, and you should almost never need to init your segment registers anyway.
yeah, of course. in a 32-bit OS it's worthless. it still has it's uses in stuff like simple bootloaders, etc.
Re: x86 Processor instruction "LDS"; When this is useful?
Posted: Tue Dec 14, 2010 7:28 pm
by pcmattman
Segment registers are still used in modern operating systems - consider FS and GS which are often used for TLS on x86. The concept of segmentation for code/data separation and protection however is mostly dead.
Re: x86 Processor instruction "LDS"; When this is useful?
Posted: Wed Dec 22, 2010 8:43 am
by jal
Hobbes wrote:And LDS, LES etcetera are guaranteed not te be interrupted, which is useful when setting up a stack (with LSS).
There's no need for using LSS for that reason, as MOV SS disables interrupts until the next instruction (typically a MOV SP). This has been the behaviour of every x86 since the 8086/88, which didn't discourage countless compiler writers to insert a cli/sti around the pair.
JAL
Re: x86 Processor instruction "LDS"; When this is useful?
Posted: Wed Dec 22, 2010 8:52 am
by qw
jal wrote:There's no need for using LSS for that reason, as MOV SS disables interrupts until the next instruction (typically a MOV SP). This has been the behaviour of every x86 since the 8086/88, which didn't discourage countless compiler writers to insert a cli/sti around the pair.
I know, but there is a small issue:
Re: x86 Processor instruction "LDS"; When this is useful?
Posted: Wed Dec 22, 2010 9:30 am
by jal
Hobbes wrote:Some exceptions may still occur; namely, page fault and general protection fault. Always use the 80386 LSS instruction, and the problem will not occur.
Ok, I thought you were talking about the 8086. Which, come to think of it, didn't have LSS, or did it?
JAL