8086- why can't we move an immediate data into segment register?

后端 未结 4 1070
南旧
南旧 2020-12-24 13:37

In 8086 assembly programming, we can only load a data into a segment register by, first loading it into a general purpose register and then we have to move it from this gene

4条回答
  •  北海茫月
    2020-12-24 14:23

    About segment registers

    The segment registers are not the same (on hardware level) as the general purpose registers. Of course, as Mike W said in the comments, the exact reason why you can't move directly immediate value into the segment register is known only by the Intel developers. But I suppose, it is because the design is simple this way. Note that this choice does not affects the processor performance, because the segment register operations are very rare. So, one instruction more, one less is not important at all.

    About syntax

    In all reasonable implementations of x86 assembler syntax, mov reg, something moves the immediate number something to the register reg. For example:

    NamedConst = 1234h
    SomeLabel:
        mov  edx, 1234h      ; moves the number 1234h to the register edx
        mov  eax, SomeLabel  ; moves the value (address) of SomeLabel to eax
        mov  ecx, NamedConst ; moves the value (1234h in this case) to ecx
    

    Closing the number in square brackets means that the content of memory with this address is moved to the register:

    SomeLabel dd 1234h, 5678h, 9abch
    
        mov  eax, [SomeLabel+4]  ; moves 5678h to eax
        mov  ebx, dword [100h]   ; moves double word memory content from the 
                                 ; address 100h in the data segment (DS) to ebx.
    

提交回复
热议问题