70,011
社区成员




#include <stdio.h>
int main()
{
int test(int x, int y, int z);
int a = 2, b = 4, c = 8;
printf("%d\n", test(a, b, c));
system("PAUSE");
return 0;
}
int test(int x, int y, int z)
{
x = y + z;
}
$ cat test.cpp
#include <stdio.h>
int main()
{
int test(int x, int y, int z);
int a = 2, b = 4, c = 8;
printf("%d\n", test(a, b, c));
return 0;
}
int test(int x, int y, int z)
{
x = y + z;
int i = 1;//添加
int j = 3;//添加
i = i + j;//添加
}
对于这样的函数:反汇编的得到:
call _Z4testiii//这里是调用
movl %eax, 4(%esp)//这里是取得返回值
movl $.LC0, (%esp)
call printf
movl $0, %eax
leave
ret
.cfi_endproc
.LFE0:
.size main, .-main
.globl _Z4testiii
.type _Z4testiii, @function
_Z4testiii:
.LFB1:
.cfi_startproc
.cfi_personality 0x0,__gxx_personality_v0
pushl %ebp
.cfi_def_cfa_offset 8
movl %esp, %ebp
.cfi_offset 5, -8
.cfi_def_cfa_register 5
subl $16, %esp
movl 16(%ebp), %eax
movl 12(%ebp), %edx
leal (%edx,%eax), %eax
movl %eax, 8(%ebp)
movl $1, -4(%ebp)
movl $3, -8(%ebp)
movl -8(%ebp), %eax//这个是最后%eax的值----3,也就是j的值,所以需要看寄存器%eax的值
addl %eax, -4(%ebp)
leave
ret
.cfi_endproc
.LFE1:
.size _Z4testiii, .-_Z4testiii
.ident "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5"
.section .note.GNU-stack,"",@progbits
call _Z4testiii //这里调用函数test
movl %eax, 4(%esp) //这里取得返回值(一般都把函数返回值放到寄存器%eax中)
movl $.LC0, (%esp)
call printf
movl $0, %eax
leave
ret
.cfi_endproc
.LFE0:
.size main, .-main
.globl _Z4testiii
.type _Z4testiii, @function
_Z4testiii:
.LFB1:
.cfi_startproc
.cfi_personality 0x0,__gxx_personality_v0
pushl %ebp
.cfi_def_cfa_offset 8
movl %esp, %ebp
.cfi_offset 5, -8
.cfi_def_cfa_register 5
movl 16(%ebp), %eax
movl 12(%ebp), %edx
leal (%edx,%eax), %eax
movl %eax, 8(%ebp)//这里是搞返回值,如果lz加上return语句,那么那个return的值应该会放到%eax寄存器中
popl %ebp
ret
.cfi_endproc
.LFE1:
.size _Z4testiii, .-_Z4testiii
.ident "GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5"
.section .note.GNU-stack,"",@progbits
int test(int x, int y, int z)
{
x = y + z;
}
//没有return的话 返回的就是一个随机的数字