struct context {
int a;
int b;
int c;
};
void f(struct context *s1, struct context *s2)
{
s2->a = s1->a;
s2->b = s1->b;
s2->c = s2->c;
}
int main()
{
struct context s1 , s2;
s1.a = 1;
s2.a = 2;
s1.b = 3;
s2.b = 4;
s1.c = 5;
s2.c = 6;
f(&s1, &s2);
return 0;
}
编译为汇编
gcc -masm=intel -S struct.c -o struct.s
struct.s 代码 (注意 64位系统 指针占用 8 个字节)
.file "struct.c"
.intel_syntax
.text
.globl f
.type f, @function
f:
.LFB2:
push %rbp
.LCFI0:
mov %rbp, %rsp
.LCFI1:
mov QWORD PTR [%rbp-8], %rdi
mov QWORD PTR [%rbp-16], %rsi
mov %rax, QWORD PTR [%rbp-8]
mov %edx, DWORD PTR [%rax]
mov %rax, QWORD PTR [%rbp-16]
mov DWORD PTR [%rax], %edx
mov %rax, QWORD PTR [%rbp-8]
mov %edx, DWORD PTR [%rax+4]
mov %rax, QWORD PTR [%rbp-16]
mov DWORD PTR [%rax+4], %edx
mov %rax, QWORD PTR [%rbp-16]
mov %edx, DWORD PTR [%rax+8]
mov %rax, QWORD PTR [%rbp-16]
mov DWORD PTR [%rax+8], %edx
leave
ret
.LFE2:
.size f, .-f
.globl main
.type main, @function
main:
.LFB3:
push %rbp
.LCFI2:
mov %rbp, %rsp
.LCFI3:
sub %rsp, 32
.LCFI4:
mov DWORD PTR [%rbp-16], 1
mov DWORD PTR [%rbp-32], 2
mov DWORD PTR [%rbp-12], 3
mov DWORD PTR [%rbp-28], 4
mov DWORD PTR [%rbp-8], 5
mov DWORD PTR [%rbp-24], 6
lea %rsi, [%rbp-32]
lea %rdi, [%rbp-16]
call f
mov %eax, 0
leave
ret
.LFE3:
.size main, .-main
.section .eh_frame,"a",@progbits
.Lframe1:
.long .LECIE1-.LSCIE1
.LSCIE1:
.long 0x0
.byte 0x1
.string "zR"
.uleb128 0x1
.sleb128 -8
.byte 0x10
.uleb128 0x1
.byte 0x3
.byte 0xc
.uleb128 0x7
.uleb128 0x8
.byte 0x90
.uleb128 0x1
.align 8
.LECIE1:
.LSFDE1:
.long .LEFDE1-.LASFDE1
.LASFDE1:
.long .LASFDE1-.Lframe1
.long .LFB2
.long .LFE2-.LFB2
.uleb128 0x0
.byte 0x4
.long .LCFI0-.LFB2
.byte 0xe
.uleb128 0x10
.byte 0x86
.uleb128 0x2
.byte 0x4
.long .LCFI1-.LCFI0
.byte 0xd
.uleb128 0x6
.align 8
.LEFDE1:
.LSFDE3:
.long .LEFDE3-.LASFDE3
.LASFDE3:
.long .LASFDE3-.Lframe1
.long .LFB3
.long .LFE3-.LFB3
.uleb128 0x0
.byte 0x4
.long .LCFI2-.LFB3
.byte 0xe
.uleb128 0x10
.byte 0x86
.uleb128 0x2
.byte 0x4
.long .LCFI3-.LCFI2
.byte 0xd
.uleb128 0x6
.align 8
.LEFDE3:
.ident "GCC: (GNU) 4.1.2 20070115 (prerelease) (SUSE Linux)"
.section .note.GNU-stack,"",@progbits