简介: CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长!
优质专栏:Audio工程师进阶系列【原创干货持续更新中……】🚀
人生格言: 人生从来没有捷径,只有行动才是治疗恐惧和懒惰的唯一良药.
1.前言
本篇目的:理解C++之生成详细汇编程序。
2.应用实例
<1>.代码示例
#include <stdio.h>
int main(void){
int i;
int a = 10;
i = a + 10;
printf("i = %d\n",i);
return 0;
}
编译: g++ -S -fverbose-asm test.cpp
<2>.生成详细的汇编代码
cat test.s
.file "test.cpp"
# GNU C++17 (Ubuntu 11.2.0-19ubuntu1) version 11.2.0 (x86_64-linux-gnu)
# compiled by GNU C version 11.2.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP
# GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
# options passed: -mtune=generic -march=x86-64 -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection
.text
.section .rodata
.LC0:
.string "i = %d\n"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
endbr64
pushq %rbp #
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp #,
.cfi_def_cfa_register 6
subq $16, %rsp #,
# test.cpp:5: int a = 10;
movl $10, -8(%rbp) #, a
# test.cpp:7: i = a + 10;
movl -8(%rbp), %eax # a, tmp87
addl $10, %eax #, tmp86
movl %eax, -4(%rbp) # tmp86, i
# test.cpp:9: printf("i = %d\n",i);
movl -4(%rbp), %eax # i, tmp88
movl %eax, %esi # tmp88,
leaq .LC0(%rip), %rax #, tmp89
movq %rax, %rdi # tmp89,
movl $0, %eax #,
call printf@PLT #
# test.cpp:11: return 0;
movl $0, %eax #, _5
# test.cpp:12: }
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Ubuntu 11.2.0-19ubuntu1) 11.2.0"
.section .note.GNU-stack,"",@progbits
.section .note.gnu.property,"a"
.align 8
.long 1f - 0f
.long 4f - 1f
.long 5
0:
.string "GNU"
1:
.align 8
.long 0xc0000002
.long 3f - 2f
2:
.long 0x3
3:
.align 8
4: