zoukankan      html  css  js  c++  java
  • GCC输出带C源代码的汇编文件

    GCC输出带C源代码的汇编文件,一共有两种方式(同样也适合G++输出呆CPP源代码的汇编文件)。
    测试代码(hello.cpp)
    1. #include<iostream>
    2. usingnamespace std;
    3. intFactorialTail(int n,int sum)
    4. {
    5. if(n <0){return0;}
    6. elseif(n ==0){return1;}
    7. elseif(n ==1){return sum;}
    8. else{returnFactorialTail(n -1, n * sum);}
    9. }
    10. int main()
    11. {
    12. cout <<FactorialTail(5,1)<< endl;
    13. return0;
    14. }
     
    第一种方式:
    1、
    1. g++-S hello.cpp
    2. g++ -g -c hello.cpp
       生成.s汇编文件和.o文件:
    _S.png
    2、第一步中必须要使用第二条命令,第一条命令只是为了显示.s汇编文件
    1. objdump -S hello.o > hello_objdump.s
    生成含有调试信息、CPP源代码的汇编代码
    objdump.png
     

    第二种方式:

    使用GNU C Assembler的列表功能来完成,例如:

    1. g++-c -g -Wa,-adlhn hello.cpp > gnu.s

    这个命令的说明如下: 
    -Wa,option :把选项option传递给汇编器.如果option含有逗号,就在逗号处分割成多个选项.也就是Gas,至于Gas的命令参数,可以查看相应的文档,其中-a[cdghlns]参数的作用是打开列表功能。

    这种方式可以显示足够的信息,但是命令稍微复杂,参数比较多,不太容易选择。

    Gas的命令行参数概要信息摘录如下:

     1:  a: -a[cdghlns] enable listings 
     2:  alternate: --alternate enable alternate macro syntax 
     3:  D: -D for compatibility 
     4:  f: -f to work faster 
     5:  I: -I for .include search path 
     6:  K: -K for difference tables 
     7:  L: -L to retain local symbols 
     8:  listing: --listing-XXX to configure listing output 
     9:  M: -M or --mri to assemble in MRI compatibility mode 
    10:  MD: --MD for dependency tracking 
    11:  o: -o to name the object file 
    12:  R: -R to join data and text sections 
    13:  statistics: --statistics to see statistics about assembly 
    14:  traditional-format: --traditional-format for compatible output 
    15:  v: -v to announce version 
    16:  W: -W, --no-warn, --warn, --fatal-warnings to control warnings 
    17:  Z: -Z to make object file even after errors 

     

    生成含有调试信息、CPP源代码的汇编代码:

    gun.png

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    相比而言,还是第一种方式生成的文件更加的直观明了。





    附件列表

  • 相关阅读:
    USACO Section 1.3 : Mixing Milk
    USACO Section 1.3 : Prime Cryptarithm
    USACO Section 1.2 : Name That Number
    USACO Section 1.3 : Calf Flac
    USACO Section 1.2 : Palindromic Squares
    Global.asax详解
    sql语句字符串处理大全
    ASP.net:URL重写实现IHttpHandler接口
    asp.net中使用基于角色role的Forms验证
    时间Table.TransformColumns(Power Query 之 M 语言)
  • 原文地址:https://www.cnblogs.com/fengkang1008/p/4652193.html
Copyright © 2011-2022 走看看