64位linux 汇编

c源码:testg.c

1 #include<stdio.h>               
2                                  
3 #define sum(a, b) a + b           
4                                   
5 int main(int argc,char **argv)   
6 {                                
7     int num = sum(1,2);         
8     printf("num =%d\n", num);  
9                                   
10     return0;                   
11
使用命令:gcc -S testg.c

寄存器:8位:al,ah

16位:ax

32位:eax

64位:rax 新增(r8-r15寄存器,低32位r8d-r15d,低16位r8w-r15w,低8位r8b-r15b)

操作符标示:8位:b

16位:w

32位:l

64位:q


1        .file   "testg.c"
2         .section        .rodata
3 .LC0:
4         .string "num = %d\n"
5         .text
6         .globl  main
7         .type   main, @function
8 main:
9 .LFB0:
10         .cfi_startproc
11         pushq   %rbp
12         .cfi_def_cfa_offset16
13         .cfi_offset6, -16
14         movq    %rsp, %rbp
15         .cfi_def_cfa_register6
16         subq    $32, %rsp
17         movl    %edi, -20(%rbp)
18         movq    %rsi, -32(%rbp)
19         movl    $3, -4(%rbp)
20         movl    -4(%rbp), %eax
21         movl    %eax, %esi
22         movl    $.LC0, %edi
23         movl    $0, %eax
24         call    printf
25         movl    $0, %eax
26         leave
27         .cfi_def_cfa7, 8
28         ret
29         .cfi_endproc
30 .LFE0:
31         .size   main, .-main
32         .ident  "GCC: (GNU)5.1.0"
33         .section        .note.GNU-stack,"",@progbits
      

linux系统中64位汇编和32位汇编的系统调用主要有以下不同:

(1)系统调用号不同.比如x86中sys_write是4,sys_exit是1;而x86_64中sys_write是1, sys_exit是60。linux系统调用号实际上定义在/usr/include/asm/unistd_32.h和/usr/include/asm/unistd_64.h中。
(2)系统调用所使用的寄存器不同,x86_64中
使用与eax对应的rax传递系统调用号,但是  
x86_64中分别使用rdi/rsi/rdx传递前三个参数,而不是x86中的ebx/ecx/edx。
(3)系统调用使用“syscall”而不是“int 80”。

posted @ 2015-06-25 07:19  叕叒双又  阅读(1788)  评论(0编辑  收藏  举报