Friday, September 12, 2025

Hello world assembly on x86 Linux

Hello world assembly on x86 Linux

Save code below as hello.asm
global _start

section .data
message: db 'hello, world!', 10

section .text
_start:
    mov     rax, 1          ; system call number should be stored in rax
    mov     rdi, 1          ; argument #1 in rdi, where to write (description)?
    mov     rsi, message    ; argument #2 in rsi, where does the string start?
    mov     rdx, 14         ; argument #3 in rdx, how many bytes to write?
    syscall                 ; this instruction invokes a system call

    mov     rax, 60         ; 'exit' syscall number
    xor     rdi, rdi
    syscall
Now assemble/build the file
nasm -felf64 hello.asm -o hello.o
Link to create executable
ld -o hello hello.o
Run it
u1@v1vm10:~$ ./hello 
hello, world!

No comments:

SBCL Hello world

SBCL Hello, world! Version info: - OS: Windows 11 23H2 (Microsoft Windows [Version 10.0.22631.7079]) - Emacs: 30.2 - SBCL : 2.6.4 - SLI...