红色部分为不同之处。代码编译 在x86_64的机器上 选择了32位模式 gcc -S 1.c -m32
默认cdecl
int add(int a,int b,int c){
int sum = a+b+c;
return sum;
};
int main(void){
int c=add(1,2,3);
}
add:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
movl 8(%ebp), %edx
movl 12(%ebp), %eax
addl %eax, %edx
movl 16(%ebp), %eax
addl %edx, %eax
movl %eax, -4(%ebp)
movl -4(%ebp), %eax
leave
ret
main:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
pushl $3
pushl $2
pushl $1
call add
addl $12, %esp
movl %eax, -4(%ebp)
movl $0, %eax
leave
ret
stdcall:
int __attribute__((__stdcall__)) add(int a,int b,int c){
int sum = a+b+c;
return sum;
};
int main(void){
int c=add(1,2,3);
}
add:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
movl 8(%ebp), %edx
movl 12(%ebp), %eax
addl %eax, %edx
movl 16(%ebp), %eax
addl %edx, %eax
movl %eax, -4(%ebp)
movl -4(%ebp), %eax
leave
ret $12
main:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
pushl $3
pushl $2
pushl $1
call add
movl %eax, -4(%ebp)
movl $0, %eax
leave
ret