-1

Consider the following example:

mov al, [variable1]

This makes sense, as you save in the register al the content (thus dereferencing it) of variable1.

Now consider this example:

mov dword L6, 1

This isn't correct; the correct form is

mov dword [L6], 1

If we're moving 1 to memory, I should tell it to be stored at that address and not at the content. Say you're telling someone to go to a certain place for a party, you'd give them the address of the party and not the people in there.

So, why is this?

  • 3
    Dereference means you're accessing the content. That is either reading from it or writing to it. You don't want to write (change) the address, which is not possible, you want to write (change) the content. – ecm Apr 08 '20 at 16:34
  • x86 doesn't have memory-indirect data addressing. It's the difference between 0 and 1 levels of indirection vs. the symbol address as an immediate, not 1 vs. 2 – Peter Cordes Apr 08 '20 at 16:40
  • if I think of mov as write it makes a lot more sense. Can I think of mov as write instead of "moving? –  Apr 08 '20 at 16:42
  • 2
    Yes. `mov` just copies from the source operand to the destination operand. That's why the destination has to be pointed-to memory or a register. – Peter Cordes Apr 08 '20 at 16:43

1 Answers1

2

x86 doesn't have memory-indirect data addressing. It's the difference between 0 and 1 levels of indirection vs. the symbol address as an immediate, not 1 vs. 2.

Unlike C, in FASM (and NASM) syntax, mentioning a bare symbol name is the address as a value.

e.g. mov eax, symbol sets EAX = the address where you put that label, with a mov eax, imm32 instruction, not a load from memory.

Of course mov symbol, eax can't work because an immediate constant can't be a destination, only a [disp32] addressing mode.

if I think of mov as write it makes a lot more sense. Can I think of mov as write instead of "moving?

Yes. mov just copies from the source operand to the destination operand. That's why the destination has to be pointed-to memory or a register. But the source operand can be an immediate, register, or memory.

(Of course you can't have both src and dst be memory for a single mov instruction; there are different forms for different kinds of operands.)


An asm symbol in FASM and NASM works kind of like C char arr[].

You can't do arr = x; - the asm equivalent is mov arr, al which isn't legal either (in FASM and NASM syntax).

But you can do *arr = x; which in asm is mov [arr], al


FYI: MASM syntax is different: instead of symbols working as a placeholder for a number in all contexts, mov sym, al is a store the same as mov [sym], al and the brackets are optional and meaningless without a register.

If you see any MASM examples or GCC/clang .intel_syntax noprefix output; that's what's going on.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847