100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Data Types and Directives

Learn how DB, DW, DD, DQ, RESB, and EQU declare initialized data, reserve uninitialized space, and define constants across .data, .bss, and .text.

Instructions & DataBeginner9 min readJul 10, 2026
Analogies

Data Types and Directives

Assembler directives like DB, DW, DD, and DQ define initialized data of increasing width: DB reserves and initializes 1 byte, DW 2 bytes (a word), DD 4 bytes (a doubleword), and DQ 8 bytes (a quadword). Unlike high-level languages, the assembler doesn't infer a type from a value's usage -- the programmer explicitly chooses the directive based on the range and precision the field needs, and every reference to that label later must use a compatible access size, such as byte, word, dword, or qword.

🏏

Cricket analogy: Recording a player's jersey number in a single-byte field on the scoreboard versus a full match date in a wider field mirrors how DB reserves one byte while DQ reserves eight bytes for larger values like 64-bit timestamps.

Reserving Uninitialized Space: RESB, RESW, RESD

When a variable's initial value doesn't matter -- like an output buffer or a counter that will be written before it's ever read -- RESB, RESW, RESD, and RESQ reserve space in the .bss section without storing any actual bytes in the executable file. The loader zero-fills this space at load time, so a large uninitialized array costs nothing in file size, unlike declaring the same array with explicit zero values in .data, which would bloat the compiled binary with every one of those zero bytes.

🏏

Cricket analogy: Reserving an empty scoreboard slot for a yet-unknown Man of the Match before the game starts mirrors RESB 1 in the .bss section, which allocates space without initializing a value, saving executable file size.

nasm
; Demonstrating DB/DW/DD/DQ and RESB in NASM
section .data
    byte_val   db  0x2A            ; 1 byte
    word_val   dw  0x1234          ; 2 bytes
    dword_val  dd  100000          ; 4 bytes
    qword_val  dq  1234567890123   ; 8 bytes
    greeting   db  "Hello", 0      ; null-terminated string

section .bss
    buffer     resb 64             ; 64 uninitialized bytes
    counters   resd 10             ; 10 uninitialized dwords

MAX_LEN equ 64

section .text
global _start
_start:
    mov ecx, MAX_LEN
    mov eax, [dword_val]
    mov eax, 1
    int 0x80

Symbolic Constants with EQU

EQU defines a symbolic constant resolved entirely by the assembler at compile time -- writing MAX_LEN equ 64 means every subsequent reference to MAX_LEN is textually substituted with 64 before the program is ever assembled, consuming zero bytes of runtime memory since it isn't a variable and can never be reassigned. This is preferred over scattering literal numbers (magic numbers) throughout the source, since a single change to the EQU definition automatically propagates to every use on the next assembly, reducing the risk of missing an occurrence.

🏏

Cricket analogy: Defining MAX_OVERS as a fixed constant of 50 once at the top of a scoring program, rather than typing 50 everywhere, mirrors MAX_OVERS equ 50, letting one change update every reference at assembly time.

NASM's TIMES directive combined with DB lets you initialize a repeated pattern compactly, e.g., zeros: times 20 db 0 reserves and zero-fills 20 bytes directly in .data, which differs from resb 20 in .bss because TIMES-initialized data actually occupies space in the executable file, while RESB reserves space that the loader zero-fills at load time without inflating the file.

Organizing Code with .data, .bss, and .text

Assembled programs are conventionally organized into three sections: .text holds executable instructions and is typically mapped read-only and executable by the OS loader; .data holds initialized, writable variables and occupies real space in the executable file; and .bss holds uninitialized, writable variables reserved with RESB/RESW/RESD/RESQ, which the loader zero-fills at load time without adding to the file's size. Keeping code and data in their correct sections isn't just stylistic -- writing to .text at runtime typically triggers a segmentation fault because of that section's read-only page protection.

🏏

Cricket analogy: Separating the match commentary script from the actual player roster and the live scoreboard display mirrors how .text holds executable instructions, .data holds initialized values, and .bss holds uninitialized reserved space, each in its own memory region.

Placing writable variables in the .text section, or forgetting that .text is typically mapped read-only and non-writable by the OS loader, causes a segmentation fault the moment the program attempts to write to that memory -- always declare mutable data in .data (initialized) or .bss (uninitialized), never alongside instructions.

  • DB, DW, DD, and DQ define initialized data of 1, 2, 4, and 8 bytes respectively.
  • RESB, RESW, RESD, and RESQ reserve uninitialized space of the same widths in the .bss section.
  • .bss data occupies no space in the executable file on disk; the OS zero-fills it at load time.
  • EQU defines a symbolic constant resolved entirely at assembly time, with zero runtime memory cost.
  • The .text section holds executable instructions and is typically marked read-only/execute by the loader.
  • The .data section holds initialized, writable variables that do occupy space in the file.
  • Mixing up which section a piece of data belongs in can cause segmentation faults or bloated binaries.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#AssemblyLanguageStudyNotes#DataTypesAndDirectives#Data#Types#Directives#Reserving#StudyNotes#SkillVeris#ExamPrep