rogram Structure
Every NASM Assembly program is divided into sections. The .data section holds initialised data, .bss holds uninitialised variables, and .text holds your executable instructions. Execution starts at the _start label.
; โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
; hello.asm โ Minimal NASM x86-64 program
; Build: nasm -f elf64 hello.asm -o hello.o
; ld hello.o -o hello
; Run: ./hello
; โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
section .data
msg db "Hello, Assembly!", 10 ; string + newline (ASCII 10)
msglen equ $ - msg ; length = current pos - start
section .bss
buf resb 64 ; reserve 64 bytes (uninitialised)
section .text
global _start ; entry point for the linker
_start:
; write(1, msg, msglen)
mov rax, 1 ; syscall: sys_write
mov rdi, 1 ; fd: stdout
mov rsi, msg ; pointer to buffer
mov rdx, msglen ; byte count
syscall ; call into the kernel
; exit(0)
mov rax, 60 ; syscall: sys_exit
xor rdi, rdi ; exit code: 0 (XOR reg,reg = fastest zero)
syscallโถ Output
Hello, Assembly!
Key Notes
- โขNASM uses Intel syntax: destination comes FIRST (mov dst, src)
- โขdb = define byte, dw = define word (2 bytes), dd = dword (4), dq = qword (8)
- โขequ is a compile-time constant โ not stored in memory
- โขresb/resw/resd/resq reserve uninitialised space in .bss
