程式語言 - Netwide Assembler (NASM) - Assembly (x64) - Hello, world!(printf)



參考資訊:
https://chromium.googlesource.com/chromiumos/docs/+/HEAD/constants/syscalls.md

main.s

    global main
    extern printf
  
    section .data
msg db "hello, world!", 10, 0
  
    section .text
main:
    push rbp
    mov rbp, rsp
    
    mov rdi, msg
    call printf
    xor rdi, rdi
 
    mov rsp, rbp
    pop rbp
    ret

編譯、執行

$ nasm -f elf64 main.s
$ x86_64-linux-gnu-gcc main.o -o main -static
$ qemu-x86_64 ./main
    hello, world!