0

What is the difference between the operations:

mov dword ptr [eax], 5

and

mov dword [eax], 5

Furthermore, do

mov dword ptr [eax], 5

and

mov [eax], dword ptr 5

do the same thing?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Ark
  • 73
  • 2
  • 8
  • 2
    Nothing, they are for different assemblers. Note that a particular assembler may accept the other syntax too and do something unexpected. `masm` uses `dword ptr` for accessing a 4 byte unit of memory but `dword [eax]` I believe gets assembled as `4[eax]` meaning `[4+eax]`. – Jester Dec 19 '20 at 20:22
  • In assemblers supporting the `dword ptr` form, the `mov [eax], dword ptr 5` is (or should be) illegal. – Jester Dec 19 '20 at 20:24
  • What about mov dword [eax], 5 vs mov [eax], dword 5 – Ark Dec 19 '20 at 20:26
  • 1
    E.g. in `nasm` those are both allowed and equivalent. You should really specify which assembler you are using. – Jester Dec 19 '20 at 20:27
  • I am using nasm. – Ark Dec 19 '20 at 20:27
  • I believe newer versions of `nasm` support more `masm` like features. But historically, `nasm` did not support `dword ptr`. – Jester Dec 19 '20 at 20:30
  • I see. Thank You. I also have another question though. If I were to write `mov [eax+10], 20`, would that be equivalent to `mov [eax+10h], 20` or `mov [eax+10d], 20` (in nasm, obviously)? – Ark Dec 19 '20 at 20:32
  • Numbers are in decimal unless otherwise stated. See [numeric constants in the manual](https://www.nasm.us/xdoc/2.11.08/html/nasmdoc3.html#section-3.4.1). – Jester Dec 19 '20 at 20:39
  • @Jester: NASM 2.15.05 (latest stable) rejects `mov dword ptr [eax], 5`, but it has a special warning to remind you that it's not NASM syntax: `warning: 'ptr' is not a NASM keyword [-w+ptr]`. Then `error: symbol 'ptr' not defined`. If you want it to assemble, you'd need to `%define ptr` (to nothing) – Peter Cordes Dec 19 '20 at 21:18

0 Answers0