Defining strings and data

Data definitions

Each directive defines data of a size: db is a byte, dw a word (2 bytes), dd a doubleword (4), dq a quadword (8). Strings are just lists of bytes:

section .data letter db "A" word_val dw 0x1234 number dd 1000000 big dq 1000000000000 name db "NASM", 0

EQU constants

EQU names a constant. It is not a variable: the value is fixed at assembly time and cannot change at run time:

SYS_EXIT equ 60 SYS_WRITE equ 1 BUF_SIZE equ 1024

TIMES padding

TIMES repeats an instruction or a data definition a fixed number of times, which is the usual way to zero a buffer or pad to an alignment:

section .bss buf resb 1024 ; 1024 reserved bytes section .data zeros times 64 db 0 ; 64 zero bytes

The code on this page was assembled with NASM 3.01 on Alpine Linux 3.24.3 (x86_64) in a Docker container.

Article author: Arthur Isaev