int main (void)
{
int i = 10;
int a = i; //优化
int b = i;
printf (“i = %d\n”, b);
return 0;
}
//编译优化、查看汇编
gcc -O2 -S test.c
cat test.s
.file “test.c”
.section .rodata.str1.1,“aMS”,@progbits,1
.LC0:
.string “i = %d\n”
.section .text.startup,“ax”,@progbits
.p2align 4,15
.globl main
.type main, @function
main:
.LFB22:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
andl $-16, %esp
subl $16, %esp
movl $10, 8(%esp)
movl $.LC0, 4(%esp)
movl $1, (%esp)
call __printf_chk
xorl %eax, %eax
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
.LFE22:
.size main, .-main
.ident “GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3”
.section .note.GNU-stack,"",@progbits
//示例二
#include <stdio.h>
int main (void)
{
volatile int i = 10;
int a = i; //未优化
int b = i;
printf (“i = %d\n”, b);
return 0;
}
//编译优化、查看汇编
gcc -O2 -S test.c
cat test.s
.file “test.c”
.section .rodata.str1.1,“aMS”,@progbits,1
.LC0:
.string “i = %d\n”
.section .text.startup,“ax”,@progbits
.p2align 4,15
.globl main
.type main, @function
main:
.LFB22:
.cfi_startproc
pushl
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》