Skip to content
Assembly

Hello World via Linux syscall

A freestanding x86-64 program that prints and exits using only kernel syscalls.

By EZ4Code Team
syscalllinuxhello-world

Code

; nasm -f elf64 hello.asm && ld hello.o -o hello && ./hello
section .rodata
    msg:     db "Hello, x86-64!", 10
    msg_len: equ $ - msg

section .text
    global _start

_start:
    ; write(1, msg, msg_len)   syscall #1
    mov     rax, 1          ; write
    mov     rdi, 1          ; fd = stdout
    lea     rsi, [rel msg]  ; buffer (RIP-relative)
    mov     rdx, msg_len
    syscall

    ; exit(0)   syscall #60
    mov     rax, 60
    xor     edi, edi
    syscall

Explanation

This is the smallest useful x86-64 Linux program — no libc, no dynamic linker. The syscall instruction enters the kernel with the syscall number in rax and up to six arguments in rdi, rsi, rdx, r10, r8, r9. write=1, exit=60. RIP-relative addressing ([rel msg]) makes the code position-independent so it works whether linked as PIE or not.

More Assembly Snippets