159

Could someone explain what this means? (Intel Syntax, x86, Windows)

and     dword ptr [ebp-4], 0
小太郎
  • 5,510
  • 6
  • 37
  • 48
  • Note that the example here is almost never what you actually want. To zero memory, use `mov dword ptr [ebp-4], 0`. Using `and` saves 3 bytes of machine-code size, using an 8-bit immediate instead of 32-bit, at the cost of performance (load/AND/store for a memory destination AND instead of just a pure store.) – Peter Cordes Jan 14 '23 at 11:20

3 Answers3

160

The dword ptr part is called a size directive. This page explains them, but it wasn't possible to direct-link to the correct section.

Basically, it means "the size of the target operand is 32 bits", so this will bitwise-AND the 32-bit value at the address computed by taking the contents of the ebp register and subtracting four with 0.

Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
unwind
  • 391,730
  • 64
  • 469
  • 606
  • 93
    The "d" in "dword" stands for "double". A word is 16 bits. – JeremyP Jun 07 '10 at 09:40
  • For more reference visit this [link](http://eli.thegreenplace.net/2010/10/21/64-bit-types-and-arithmetic-on-32-bit-cpus/) – Alex Mathew Mar 18 '14 at 06:34
  • 42
    Why is the `PTR` part needed? Isn't dword enough to encode the size? NASM does not use `ptr` AFAIK. – Ciro Santilli OurBigBook.com Jun 20 '15 at 16:55
  • 1
    @JeremyP Word mean is changing according to processors. After reading this article can you say again word is 16 bits or you are only defining the simple meaning of word which means two bytes? `Modern processors, including embedded systems, usually have a word size of 8, 16, 24, 32, or 64 bits, while modern general purpose computers usually use 32 or 64 bits.` https://en.wikipedia.org/wiki/Word_(computer_architecture) – uzay95 Dec 25 '16 at 21:35
  • 8
    @uzay95 The question is tagged "x86" so we are talking **specifically** about the Intel x86 architecture, in which a word is 16 bits wide. According to your article, even the x86_64 has a word size of 16 bits. – JeremyP Dec 27 '16 at 11:27
  • Thanx a lot , finally I understood this directive – krachleur Jan 06 '18 at 12:31
  • 2
    @CiroSantilli新疆再教育营六四事件法轮功郝海东 Did you figure out why `PTR` is needed? – pmor Feb 09 '22 at 17:49
  • 1
    @pmor nope. And I moved to GAS later as it is slightly more cross arch. Try asking Peter Cordes. – Ciro Santilli OurBigBook.com Feb 09 '22 at 19:54
11

Consider the figure enclosed in this other question. ebp-4 is your first local variable and, seen as a dword pointer, it is the address of a 32 bit integer that has to be cleared. Maybe your source starts with

Object x = null;
Community
  • 1
  • 1
mico
  • 1,816
  • 1
  • 18
  • 27
7

It is a 32bit declaration. If you type at the top of an assembly file the statement [bits 32], then you don't need to type DWORD PTR. So for example:

[bits 32]
.
.
and  [ebp-4], 0
L4m0r
  • 97
  • 1
  • 2