GNU >> Assembly (x86)

hello, world! (sysenter)


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

main.s

    .global _start
    
    .data
msg: .ascii "hello, world!\n"
len = . - msg
  
    .text
_start:
    push %ebp
    mov %esp, %ebp

    mov $4, %eax
    mov $1, %ebx
    mov $msg, %ecx
    mov $len, %edx
    push $final
    push %ecx
    push %edx
    push %ebp
    mov %esp, %ebp
    sysenter

final:
    mov $1, %eax
    mov $0, %ebx
    push $final
    push %ecx
    push %edx
    push %ebp
    mov %esp, %ebp
    sysenter

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

編譯、執行

$ gcc -m32 main.s -o main -nostdlib
$ ./main
    hello, world!

P.S. 於Debian x64環境測試


返回上一頁