• C++之生成详细汇编代码(二百一十六)


    简介: CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长!

    优质专栏:Audio工程师进阶系列原创干货持续更新中……】🚀

    人生格言: 人生从来没有捷径,只有行动才是治疗恐惧和懒惰的唯一良药.

    更多原创,欢迎关注:Android系统攻城狮

    欢迎关注Android系统攻城狮

    1.前言

    本篇目的:理解C++之生成详细汇编程序。

    2.应用实例

    <1>.代码示例

    #include 
    
    int main(void){
      int i;
      int a = 10;
    
      i  = a + 10;
    
      printf("i = %d\n",i);
    
      return 0;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    编译: 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:
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
  • 相关阅读:
    span标签的作用
    7.7亿参数,超越5400亿PaLM!UW谷歌提出「分步蒸馏」,只需80%训练数据|ACL 2023
    Vue ref属性
    计算机视觉和机器视觉有什么区别?
    常见视频传输接口
    企业电子杂志如何制作与分享
    今天是1024节日,作为一个程序员,我想表达我对Java和詹姆斯·高斯林(James Gosling)的感激之情
    40度高温,如何通过SOLIDWORKS找到室内最凉快的地方?
    sql1(Leetcode1757可回收且低脂的产品)
    vis实现类知识图谱的拓扑图
  • 原文地址:https://blog.csdn.net/u010164190/article/details/132892619