程式語言 - Netwide Assembler (NASM) - Assembly (x86) - Hello, world!(gs)



參考資訊:
https://stackoverflow.com/questions/41690592/what-does-gs0x10-do-in-assembler
https://chromium.googlesource.com/chromiumos/docs/+/HEAD/constants/syscalls.md
https://reverseengineering.stackexchange.com/questions/2869/how-to-use-sysenter-under-linux

System Call

NRsyscall nameeaxarg0(ebx)arg1(ecx)arg2(edx)
1exit1int error_code
4write4unsigned int fdconst char *bufsize_t count

main.s

    global main
  
    section .data
msg db "hello, world!", 10
len equ $ - msg
  
    section .text
main:
    mov eax, 4
    mov ebx, 1
    mov ecx, msg
    mov edx, len
    call [gs:0x10]
    
    mov eax, 1
    mov ebx, 0
    call [gs:0x10]

編譯、執行

$ nasm -f elf32 main.s
$ i686-linux-gnu-gcc main.o -o main -static
$ qemu-i386 ./main
    hello, world!