程式語言 - GNU - Assembly (x64) - Hello, world!(printf)



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

main.s

    .global main
    .extern printf
  
    .data
msg: .asciz "hello, world!\n"
  
    .text
main:
    push %rbp
    mov %rsp, %rbp
    
    mov $msg, %rdi
    call printf
    xor %rdi, %rdi
 
    mov %rbp, %rsp
    pop %rbp
    ret

編譯、執行

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