Labels and Entry Point ( start)
Labels and Entry Point (_start)
This page explains how labels work in assembly programming and how the program’s entry point is defined.
What are labels
A label is a symbolic name for a memory address. It marks a location in code or data that can be referenced later.
Syntax:
LabelName:
Example:
SECTION .data EatMsg: db "Eat at Joe’s"
SECTION .text mov rcx, EatMsg ; rcx ← address of the string mov rdx, [EatMsg] ; rdx ← first 8 bytes of the string
Here:
- EatMsg refers to the address of the string.
- [EatMsg] refers to the contents at that address.
Why labels are needed
Labels replace hardcoded addresses and make programs relocatable:
- You don’t know where in memory your program will be loaded.
- The linker can adjust label references automatically.
- The code becomes modular and position-independent.
Code labels
Labels can also be attached to code lines. They mark destinations for jumps and branches, forming the basis for control flow.
Example:
mov eax, 5
loop_start:
dec eax jnz loop_start ; jump back if eax ≠ 0
Here, loop_start marks the instruction to jump to. Such code labels are essential for loops, branches, and function calls.
The _start label
_start: defines the entry point of an assembly program on Linux. It is the first instruction executed when the program runs.
Example:
global _start
_start:
mov rax, 60 ; system call for exit xor rdi, rdi ; return code 0 syscall
- The keyword global makes _start visible to the linker.
- The operating system looks for this symbol to know where to begin execution.
Every NASM program for Linux must define exactly one entry point, usually called _start.
Summary
- Labels are symbolic names for addresses.
- Data labels point to memory locations.
- Code labels mark positions for jumps.
- The _start label defines where execution begins.