14
and     dword ptr [ebp-4], 0

In assembly code like above, what does the term PTR stand for? I know their usage -- size directives; but where had the term PTR been coined from? Does it stand for PoinTeR?

I've read:

Community
  • 1
  • 1

1 Answers1

20

The point of this hint is to tell the size of the operand.

You're writing to a point in memory. As you're only giving a 0, it doesn't know if it should write a byte, or word, or doubleword. The dword ptr means "write a doubleword". Yes, it stands for pointer, because you put a memory address as destination.

z0rberg's
  • 674
  • 5
  • 10
  • 5
    Why is PTR required? Why isn't DWORD sufficient to infer the size of the operand? Is this just a syntatical quirk? – jonny Apr 21 '19 at 14:33
  • 5
    @jonny Yes, it is pretty much a syntactical quirk. Most modern (Intel-compatible) assemblers would accept `and [ebp-4], 0`, `and dword [ebp-4], 0` and `and dword ptr [ebp-4], 0` as the same. – Toothbrush Sep 17 '19 at 13:41
  • 4
    @Toothbrush: good assemblers will reject `and [ebp-4], 0` as ambiguous operand-size: do you want to zero a byte, word, dword, or qword. [Determining when NASM can infer the size of the mov operation](https://stackoverflow.com/q/30959266). Less-good assemblers have a default, often dword (like GAS for non-mov insns); with really bad assemblers like emu8086, the size depends on the numeric constant!!! Also, there aren't any assemblers AFAIK that will accept both `dword` and `dword ptr`. MASM will assemble `dword` as the constant number 4, so `4[ebp-4]` = `[ebp - 4 + 4]` = `[ebp]`. – Peter Cordes Dec 20 '20 at 02:26
  • @PeterCordes I've seen and used both `DWORD` and `DWORD PTR` in NASM and LLVM (Intel-syntax) assembly blocks. I'm not so sure about the `and [ebp-4], 0` syntax; I'm pretty sure I've used it in NASM in the past. – Toothbrush Dec 22 '20 at 14:31
  • 2
    @Toothbrush: NASM and GNU .intel_syntax are different. NASM chokes on `dword ptr`, GAS / LLVM choke on `dword`. With NASM 2.15.05 assembling MASM/GNU syntax: `warning: 'ptr' is not a NASM keyword [-w+ptr]` / `error: symbol 'ptr' not defined`. And for clang/LLVM assembling NASM syntax, we get `error: Expected 'PTR' or 'ptr' token!`. With actual GAS, we get `Error: ambiguous operand size for 'add'` from `add dword [ebp - 4], 0`, but with `add dword [ebp-4], eax` the disassembly is `add dword ptr [ebp+0], eax`. – Peter Cordes Dec 22 '20 at 18:56
  • 1
    @Toothbrush: As for `and [ebp-4], 0` without a size specifier, no, current NASM definitely rejects that: `error: operation size not specified`. Older NASM might have been bad and had some default, but more likely you're mis-remembering. (Older GAS didn't use to error or warn about ambiguous operand-size on instructions other than mov; I think that was a change in the past few months. But not for NASM.) – Peter Cordes Dec 22 '20 at 18:58