at&a 64汇编
作者:互联网
1.第一个at&a 64汇编
1 .section .data 2 strFormat: 3 .asciz "%s\n" 4 strUseLibc: 5 .asciz "Hi, If you see me, you called c lib :)" 6 strUseSyscall: 7 .asciz "And if you see me, you called syscall.\n" 8 endOfStrUseSyscall: 9 10 .section .text 11 .globl _start 12 _start: 13 # 函数调用的传参已经不再单纯使用压栈的方式 14 movq $strFormat, %rdi 15 movq $strUseLibc, %rsi 16 call printf 17 18 # 系统调用的寄存器已经改变,int 0x80 也被syscall 替代 19 movq $1, %rdi 20 movq $strUseSyscall, %rsi 21 movq $(endOfStrUseSyscall-strUseSyscall), %rdx 22 movq $1, %rax 23 syscall 24 25 #另外系统调用的编号也不同了 26 movq $127, %rdi # 故意返回一个非0 值 27 movq $60, %rax 28 syscall
2 从c 转成汇编,再编译成bin
GCC 编译的背后
http://tinylab.org/behind-the-gcc-compiler/
1 #include <stdio.h> 2 #include <unistd.h> 3 4 int sum(int a) { 5 return a; 6 } 7 int main() { 8 int b = 0; 9 b = sum(1); 10 printf("hello:%d\n", b); 11 _exit(0); 12 }
1 gcc -S test.c -fno-asynchronous-unwind-tables -fno-exceptions -fno-stack-protector 2 sed -i -e "s#main#_start#g" test.s 3 gcc -c test.s 4 #ld -o test test.o /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o /usr/lib/x86_64-linux-gnu/crtn.o -lc --dynamic-linker /lib64/ld-linux-x86-64.so.2 5 ld -o test test.o -lc --dynamic-linker /lib64/ld-linux-x86-64.so.2
标签:汇编,x86,int,64,linux,test,movq 来源: https://www.cnblogs.com/mysqlinternal/p/12736401.html