Search code examples
assemblyx86nasmmasmmemory-segmentation

moving memory operand to segment register,assembly(x86)


Are we able to move a memory operand to a segment register in these ways using MOV instruction in assembly(x86) language ?

1.

MOV DS,[BX]

2.

MOV DS,[6401H]


Solution

  • Yes, both addressing modes are valid.

    You've got this question tagged both Masm and Nasm. They're not the same, y'know! To convince Masm you want a memory reference, you may need to do mov ds, ds:[6401h] - strange, I know, but that's the syntax of the assembler - or was, the last time I used Masm (long time ago!). The redundant ds: is optimized away in Masm, Nasm would emit it. If Fasm won't do this, Fasm is broken (which I doubt! Tomasz is a genius!)... just tried it with Fasm - works fine!

    Incidentally, 32-bit addresses do involve a segment register - the OS sets 'em up, and it is rare to use 'em in "userland" code, but they're still there! (64-bit code, no - but I'm less sure of that).