分类: C/C++
2009-08-25 21:03:11
void return_test(void *temp) { big_thing b; b.buf[0] = 0; memcpy(temp, &b, sizeof(big_thing)); eax = temp; } int main() { big_thing temp; big_thing n; return_test(&temp); memcpy(&n, eax, sizeof(big_thing)); } |
int main() { big_thing n; return_test(&n); } |
typedef struct big_thing { char buf[128]; } big_thing; big_thing return_test () { big_thing b; b.buf[0] = 0; return b; } int main() { big_thing n = return_test(); return 0; } |
.file "t_ret_struct.c" .text .globl return_test .type return_test, @function return_test: pushl %ebp movl %esp, %ebp pushl %ebx subl $148, %esp movl 8(%ebp), %ebx movb $0, -136(%ebp) movl %ebx, %ecx leal -136(%ebp), %edx movl $128, %eax movl %eax, 8(%esp) movl %edx, 4(%esp) movl %ecx, (%esp) call memcpy movl %ebx, %eax addl $148, %esp popl %ebx popl %ebp ret $4 .size return_test, .-return_test .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $152, %esp andl $-16, %esp movl $0, %eax addl $15, %eax addl $15, %eax shrl $4, %eax sall $4, %eax subl %eax, %esp leal -136(%ebp), %eax movl %eax, (%esp) call return_test subl $4, %esp movl $0, %eax leave ret .size main, .-main .section .note.GNU-stack,"",@progbits .ident "GCC: (GNU) 3.4.6 (Debian 3.4.6-10)" |
.file "t_ret_struct.c" .text .globl return_test .type return_test, @function return_test: pushl %ebp movl %esp, %ebp pushl %ebx subl $148, %esp #temp struct movl 8(%ebp), %ebx #dest movb $0, -132(%ebp) # movl %ebx, %ecx leal -132(%ebp), %edx #dest movl $128, %eax movl %eax, 8(%esp) movl %edx, 4(%esp) movl %ecx, (%esp) call memcpy movl %ebx, %eax addl $148, %esp popl %ebx popl %ebp ret $4 .size return_test, .-return_test .globl main .type main, @function main: leal 4(%esp), %ecx andl $-16, %esp pushl -4(%ecx) pushl %ebp movl %esp, %ebp pushl %ecx subl $132, %esp leal -132(%ebp), %eax movl %eax, (%esp) call return_test subl $4, %esp movl $0, %eax movl -4(%ebp), %ecx leave leal -4(%ecx), %esp ret .size main, .-main .ident "GCC: (GNU) 4.1.3 20080704 (prerelease) (Debian 4.1.2-26)" .section .note.GNU-stack,"",@progbits |
.file "t_ret_struct.c" .text .globl return_test .type return_test, @function return_test: pushl %ebp movl %esp, %ebp pushl %edi pushl %esi subl $140, %esp movl 8(%ebp), %eax movb $0, -136(%ebp) movl %eax, -140(%ebp) leal -136(%ebp), %edx movl %edx, -144(%ebp) movl $32, -148(%ebp) movl -140(%ebp), %edi movl -144(%ebp), %esi movl -148(%ebp), %ecx rep movsl addl $140, %esp popl %esi popl %edi popl %ebp ret $4 .size return_test, .-return_test .globl main .type main, @function main: leal 4(%esp), %ecx andl $-16, %esp pushl -4(%ecx) pushl %ebp movl %esp, %ebp pushl %ecx subl $132, %esp leal -132(%ebp), %eax movl %eax, (%esp) call return_test subl $4, %esp movl $0, %eax movl -4(%ebp), %ecx leave leal -4(%ecx), %esp ret .size main, .-main .ident "GCC: (Debian 4.3.4-1) 4.3.4" .section .note.GNU-stack,"",@progbits |
typedef struct big_thing { char buf[128]; } big_thing; big_thing return_test () { big_thing b; b.buf[0] = 0; return b; } big_thing n; int main() { n = return_test(); return 0; } |
.file "t.c" .text .globl return_test .type return_test, @function return_test: pushl %ebp movl %esp, %ebp pushl %edi pushl %esi subl $140, %esp movl 8(%ebp), %eax movb $0, -136(%ebp) movl %eax, -140(%ebp) leal -136(%ebp), %edx movl %edx, -144(%ebp) movl $32, -148(%ebp) movl -140(%ebp), %edi movl -144(%ebp), %esi movl -148(%ebp), %ecx rep movsl addl $140, %esp popl %esi popl %edi popl %ebp ret $4 .size return_test, .-return_test .globl main .type main, @function main: leal 4(%esp), %ecx andl $-16, %esp pushl -4(%ecx) pushl %ebp movl %esp, %ebp pushl %edi pushl %esi pushl %ecx subl $160, %esp leal -152(%ebp), %eax movl %eax, (%esp) call return_test subl $4, %esp movl $n, -156(%ebp) leal -152(%ebp), %eax movl %eax, -160(%ebp) movl $32, -164(%ebp) movl -156(%ebp), %edi movl -160(%ebp), %esi movl -164(%ebp), %ecx rep movsl movl $0, %eax leal -12(%ebp), %esp popl %ecx popl %esi popl %edi popl %ebp leal -4(%ecx), %esp ret .size main, .-main .comm n,128,32 .ident "GCC: (Debian 4.3.4-1) 4.3.4" .section .note.GNU-stack,"",@progbits |