Data Definition Directives: db, dw, dd, dq, equ
Data Definition Directives (db, dw, dd, dq, equ)
Assembly language provides directives to define data in memory. These specify how many bytes are allocated and what values they hold.
Overview
Data definition directives do not generate executable code — they reserve and optionally initialize memory. They are primarily used in the **.data** and **.bss** sections.
Common Directives
| Directive | Meaning | Size per Element | Typical Use |
|------------|-------------------|------------------|--------------------------------------|
| db | Define Byte | 1 byte | Characters, small values |
| dw | Define Word | 2 bytes | 16-bit integers |
| dd | Define Doubleword | 4 bytes | 32-bit integers or floats |
| dq | Define Quadword | 8 bytes | 64-bit integers, pointers |
| equ | Define Constant | none | Named constant, no memory allocation |
Examples
SECTION .data MyByte: db 0x07 ; single byte (7) MyWord: dw 0x0FFFF ; 16-bit value MyDouble: dd 0x0B8000000 ; 32-bit value MyQuad: dq 0x0B800000011000000 ; 64-bit value Text: db "Assembly Rocks!",10 ; string with newline Len: equ $ - Text ; calculate string length
db — Define Byte
Defines one or more bytes. Each element can be a value, character, or string.
Example:
db 72, 101, 108, 108, 111, 0 db "Hello", 0
Each character literal expands to its ASCII value. Strings can include escape sequences such as `10` for newline (LF).
dw, dd, dq — Define Larger Values
These define 2, 4, or 8-byte values respectively.
Example:
dw 0x1234 ; 2 bytes dd 0x12345678 ; 4 bytes dq 0x1122334455667788 ; 8 bytes
They are often used for integers, addresses, or floating-point constants.
equ — Define Constant
equ (short for *equate*) defines a constant symbol. It **does not** allocate memory, but replaces the symbol with a numeric value at assembly time.
Example:
Count: equ 10 mov ec