NASM syntax basics

Sections

A NASM program is divided into sections. .text holds code, .data holds initialized data, and .bss holds uninitialized reserves. The section directive switches between them:

section .text mov rax, 1 section .data count dq 0

Labels

A label names a position in the code or a byte of data. Labels end with a colon, and the assembler turns them into addresses:

start: mov rax, 1 jmp start

Operands

Most instructions take two operands: destination first, source second. The destination is where the result lands, and the source is what gets moved or added. Comments start with a semicolon:

mov rax, rbx ; copy rbx into rax add rax, 1 ; rax = rax + 1

Next: Your first program

Article author: Arthur Isaev

Banner image