LOGBOOK

HELP

1 / 46
Other keys: showSpace: good1-4: rate0: skip5: flag6: invert

Question

What are the two main sections in an x86 assembly program and what does each contain?

Answer

.text holds the executable code (functions and instructions); .data holds initialized global/static variables.

An x86 assembly program branching into three section boxes: .text for read-only executable code, .data for initialized read/write global data, and .rodata for read-only constants and jump tables.

* The main assembler sections: .text holds executable code, .data holds initialized read/write globals, and .rodata holds read-only constants. *

An assembly file has no functions or variables in the C sense — it has labeled regions of bytes placed into named sections, and the linker decides where each section ends up in the final program's address space. A section directive like .text or .data simply tells the assembler "everything below here belongs in this section, until I say otherwise."

Section Purpose Typical content
.text Executable code (usually read-only at runtime) Function bodies, instructions
.data Initialized read/write global data Strings, constants, global variables
.text
.align 16
.globl main
main:
    movl $1, %eax
    ...
    ret

.data
.align 16
hstr:
    .ascii "Hello, world!\n"

A label (like main: or hstr:) is just a human-readable alias for the address where the next byte lands — in .text it names a function or jump target, in .data it names a variable.

Tip: Read-only constants and jump tables often go in a third section, .rodata (read-only data), so the OS can mark those pages non-writable.

Go deeper:

or press any other key