Author Topic: Mov instruction with segment register  (Read 3164 times)


  • Regular Member
  • *
  • Posts: 7
Mov instruction with segment register
« on: October 06, 2015, 02:25:41 PM »

Hi All,

I have a question. What is the reason for limitation of mov instruction with segment register. For example the following instruction
Code: [Select]
mov ds, es


  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: Mov instruction with segment register
« Reply #1 on: October 06, 2015, 09:17:46 PM »
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:
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:
In 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:
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.

Well Microsoft, here’s another nice mess you’ve gotten us into.


  • Member
  • **
  • Posts: 115
Re: Mov instruction with segment register
« Reply #2 on: October 07, 2015, 12:55:41 AM »
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  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.


  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: Mov instruction with segment register
« Reply #3 on: October 07, 2015, 07:21:55 AM »
we used to see....
Code: [Select]
    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

Code: [Select]
wSeg dw 40h

    mov     es,wSeg