Hello, x86_64!
Your First x86_64 Program
x86_64 (also called AMD64) is the dominant desktop and server processor architecture. It powers nearly every laptop, desktop, and cloud server you use. Learning x86_64 assembly gives you a direct view into how your computer really works.
Program Structure
An x86_64 assembly program in Intel syntax has two main sections:
section .data-- holds your data (strings, numbers, buffers)section .text-- holds your code (instructions)
The _start label marks where execution begins. The global _start directive makes it visible to the system.
Registers
x86_64 has 16 general-purpose 64-bit registers:
| Register | Typical Use |
|---|---|
rax | Return value, syscall number |
rbx | Callee-saved general purpose |
rcx | Counter for loops |
rdx | Syscall arg 3, I/O |
rsi | Syscall arg 2 (source index) |
rdi | Syscall arg 1 (destination index) |
rsp | Stack pointer |
rbp | Base pointer (frame pointer) |
r8-r15 | Additional general purpose |
Linux x86_64 Syscalls
On Linux x86_64, you invoke a syscall by:
- Setting
raxto the syscall number - Setting arguments in
rdi,rsi,rdx,r10,r8,r9 - Executing the
syscallinstruction
For sys_write (syscall 1):
rdi= file descriptor (1 = stdout)rsi= pointer to the string in memoryrdx= length of the string
For sys_exit (syscall 60):
rdi= exit code
Loading Addresses
To load the address of a data label into a register, use lea (load effective address):
lea rsi, [msg] ; rsi now holds the address of msg
Your Task
Write a program that prints exactly Hello, x86_64!\n (15 characters) to stdout using the write syscall, then exits with code 0.