Netwide Assembler (NASM) >> Assembly (x86)

hello, world! (sysenter)


參考資訊:
1. syscall
2. 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 _start
   
    section .data
msg db "hello, world!", 10
len equ $ - msg
   
    section .text
_start:
    push ebp
    mov ebp, esp

    mov eax, 4
    mov ebx, 1
    mov ecx, msg
    mov edx, len
    push ret
    push ecx
    push edx
    push ebp
    mov ebp, esp
    sysenter
 
ret:
    mov eax, 1
    mov ebx, 0
    push ret
    push ecx
    push edx
    push ebp
    mov ebp, esp
    sysenter

編譯、執行

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

P.S. 於Debian x64環境測試


返回上一頁