Memory layout: sections

The three sections

Every NASM program declares its memory in sections. .text is code and is read-only, .data is initialized data, and .bss is reserved-but-zero storage that takes no space in the file:

section .text global _start section .data msg db "hi", 10 section .bss buf resb 4096

Why .bss is free

A .bss reserve costs nothing in the file: the ELF header records the size, and the kernel zeroes the pages when it loads the program. A 4 KB buffer in .data would add 4 KB to the file; in .bss it adds nothing.

The process image

The loader maps .text at a low address, .data after it, then .bss, then the heap, and the stack at the top of the address space. Section order in your source does not decide the layout: the linker script does.

Next: Linux syscalls

Article author: Arthur Isaev