C代码
#include <stdio.h>
typedef struct S {
short a;
int b;
long c;
long d;
long e;
long f;
long g;
long h;
short i;
} S;
void foo(S s) {
printf("%hd, %d, %ld, %ld, %ld, %ld, %ld, %ld, %hd\n",
s.a, s.b, s.c, s.d, s.e, s.f, s.g, s.h, s.i);
}
int main() {
S s = {1, 2, 3, 4, 5, 6, 7, 8, 9};
foo(s);
printf("%ld\n", sizeof(short));
}
gcc -S -g test.c
生成的汇编代码
.file "test_align.c"
.text
.Ltext0:
.section .rodata
.align 8
.LC0:
.string "%hd, %d, %ld, %ld, %ld, %ld, %ld, %ld, %hd\n"
.text
.globl foo
.type foo, @function
foo:
.LFB0:
.file 1 "test_align.c"
.loc 1 14 0
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
.loc 1 17 0
movzwl 72(%rbp), %eax
.loc 1 16 0
movswl %ax, %r9d
movq 64(%rbp), %r8
movq 56(