Hi All,
I have a question. What is the reason for limitation of mov instruction with segment register. For example the following instruction
mov ds, es
Regards,
Arka
I don't have any way to test any of this, but basically I think the reason is that the segment registers are not normal registers. From the Intel manual:
Quote
If the destination operand is a segment register (DS, ES, FS, GS, or SS), the source operand must be a valid
segment selector.
The manual continues with what happens in protected mode:
QuoteIn protected mode, moving a segment selector into a segment register automatically causes the segment descriptor information associated with that segment selector to be loaded into the hidden (shadow) part of the segment register. While loading this information, the segment selector and segment descriptor information is validated (see the "Operation" algorithm below). The segment descriptor data is obtained from the GDT or LDT entry for the specified segment selector.
But nothing about real mode.
And regarding CS:
Quote
The MOV instruction cannot be used to load the CS register. Attempting to do so results in an invalid opcode exception (#UD). To load the CS register, use the far JMP, CALL, or RET instruction.
The reason, well, as far as design, you'd have to ask the Intel engineers to be sure. Practically speaking, the design has "sregs" in a different class from the standard "r/m" encoding. See http://ref.x86asm.net/coder32.html. My guess on their intentions is that it's not something you'd normally do tons of and the bits/transistor budget was better spent elsewhere.
we used to see....
push es
pop ds
to get around that one
also note that you cannot load a segment register with an immediate constant
you can, however, load it with a variable
wSeg dw 40h
mov es,wSeg