21

DB allocates in chunks of 1 byte.

DW allocates in chunks of 2 bytes.

DD allocates in chunks of 4 bytes.

DQ allocates in chunks of 8 bytes.

So I assume that:

RESB 1 allocates 1 byte.

RESW 1 allocates 2 bytes.

RESD 1 allocates 4 bytes.

RESQ 1 allocates 8 bytes.

Am I correct?


The documentation doesn't say much:

3.2.2 RESB and Friends: Declaring Uninitialized Data

RESB, RESW, RESD, RESQ, REST, RESO, RESY and RESZ are designed to be used in the BSS section of a module: they declare uninitialized storage space. Each takes a single operand, which is the number of bytes, words, doublewords or whatever to reserve. As stated in section 2.2.7, NASM does not support the MASM/TASM syntax of reserving uninitialized space by writing DW ? or similar things: this is what it does instead. The operand to a RESB-type pseudo-instruction is a critical expression: see section 3.8.

For example:

buffer: resb 64 ; reserve 64 bytes

wordvar: resw 1 ; reserve a word

realarray resq 10 ; array of ten reals

ymmval: resy 1 ; one YMM register

zmmvals: resz 32 ; 32 ZMM registers

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
user8240761
  • 975
  • 1
  • 10
  • 15
  • 2
    yes, you're correct. The docs seem pretty clear to me. – Peter Cordes Jul 01 '17 at 10:45
  • You need to think about what you have written. `RESB 64` clearly says "reserve 64 things that are 1 byte in length" – David Hoelzer Jul 01 '17 at 12:55
  • @David Hoelzer Yes I noticed that, but the documentation only speaks clearly about `resb` and not the rest. – user8240761 Jul 01 '17 at 13:51
  • 2
    I'm not sure what is unclear about the documentation. Do you not know what they mean when they say "word"? This section is meant to be read *after* reading [the previous section](http://www.nasm.us/xdoc/2.11.06/html/nasmdoc3.html#section-3.2.1), since it uses the same type suffixes. – Cody Gray - on strike Jul 01 '17 at 14:56

1 Answers1

13

Am I correct?

yes.

The size suffixes are consistent throughout NASM, for d* and res*. They match x86 instruction mnemonic suffixes for byte to qword. (e.g. psubd works with packed dword elements).

There's even an instruction mnemonic that uses o (oct-word): cqo.

y and z size suffixes obviously match ymm and zmm register sizes, even though the instruction mnemonics are now things like VBROADCASTI32X8 because of AVX512 masking granularity.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Well, more or less consistent. Intel occasionally comes up with silly and confusing terminology like `dq` (double-quad) words instead of owords. `rest` reserves ten _bytes_ and not a pentaword . Still, I would advocate checking the listing and or debugger to see actual result in this case. – doynax Jul 01 '17 at 10:53
  • @doynax: that's why I said it matches mnemonics up to qword, because of `movdqa/u`, `movntdq/dqa`, and the amusingly named `punpckhqdq` (unpack qword to dqword), and so on. Or `cmpxchg16b`. Intel's documentation never talks about `m80` x87 operands as TBYTE or penta-word or anything like that, they just say 80-bit if they name it at all. Or for example ["18-digit packed BCD integer"](http://felixcloutier.com/x86/FBSTP.html). – Peter Cordes Jul 01 '17 at 10:59
  • Also related: [What are the sizes of tword, oword and yword operands?](https://stackoverflow.com/q/12063840) / [What comes after QWORD?](https://stackoverflow.com/q/39645078) – Peter Cordes Jun 04 '21 at 02:46