Lesson 1 of 15

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:

RegisterTypical Use
raxReturn value, syscall number
rbxCallee-saved general purpose
rcxCounter for loops
rdxSyscall arg 3, I/O
rsiSyscall arg 2 (source index)
rdiSyscall arg 1 (destination index)
rspStack pointer
rbpBase pointer (frame pointer)
r8-r15Additional general purpose

Linux x86_64 Syscalls

On Linux x86_64, you invoke a syscall by:

  1. Setting rax to the syscall number
  2. Setting arguments in rdi, rsi, rdx, r10, r8, r9
  3. Executing the syscall instruction

For sys_write (syscall 1):

  • rdi = file descriptor (1 = stdout)
  • rsi = pointer to the string in memory
  • rdx = 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.

x86_64 runtime loading...
Loading...
Click "Run" to execute your code.