Netwide Assembler (NASM) >> Assembly (x64)

hello, world! (syscall)


參考資訊:
1. syscall
2. how-to-use-sysenter-under-linux

System Call

NRsyscall nameraxarg0(rdi)arg1(rsi)arg2(rdx)
1write1unsigned int fdconst char *bufsize_t count
60exit60int error_code

main.s

    global _start

    section .data
msg db "hello, world!", 10
len equ $ - msg

    section .text
_start:
    mov rax, 1
    mov rdi, 1
    mov rsi, msg
    mov rdx, len
    syscall

    mov rax, 60
    xor rdi, rdi
    syscall

編譯、執行

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


返回上一頁