1. 程式人生 > >[ASM]Linux x86_64平臺彙編例項

[ASM]Linux x86_64平臺彙編例項

【環境】
CentOS 7 x86_64
Linux 3.10.0-229.7.2.el7.x86_64
NASM 2.10.07 x86_64

【程式:hello.asm】

; 64-bit "Hello World!" in CentOS 7 x86_64

global _start           ; global entry point export for ld

_start:
    jump short string   ; get message addr

code:
    ; sys_write(stdout, message, length)
    pop     rsi         ; message address
    mov     rax, 1
; sys_write mov rdi, 1 ; stdout mov rdx, 13 ; message string length + 0x0a syscall ; sys_exit(return_code) mov rax, 60 ; sys_exit mov rdi, 0 ; return 0 (success) syscall string: call code db 'Hello world!',0x0a ; message and
newline

【編譯與執行】

[hello@local asm]$ nasm -f elf64 hello.asm -o hello.o
[hello@local asm]$ ld -s -o hello hello.o
[hello@local asm]$ ./hello

【提取】

[[email protected] asm]$ for i in $(objdump -d hello |grep "^ " |cut -f2); do echo -n '\x'$i; done; echo