打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
GCC输出带C源代码的汇编文件
userphoto

2011.11.28

关注

http://blog.csdn.net/lanxinju/article/details/5900986

摘要: 使用GCC输出带C源代码的汇编文件,这样便于对应着源代码来查看汇编代码
关键字: GCC  源代码 汇编

使用GCC输出带C源代码的汇编文件有两种方式,

第一种方式

gcc –c –S source.c
objdump –S source.o

首先生成带生成目标文件,然后使用objdump命令,显示源代码与汇编代码的混合文件

这种方式生成的信息较少,但是主要的信息是足够了

-S, --source             Intermix source code with disassembly

第二种方式

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

gcc –c –g –Wa,-adlhn source.c > source.s

这个命令的说明如下:
-Wa,option :把选项option传递给汇编器.

  -Wa,<options>            Pass comma-separated <options> on to the assembler

  -Wp,<options>            Pass comma-separated <options> on to the preprocessor

  -Wl,<options>            Pass comma-separated <options> on to the linker


如果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 

 

Gas的在线文档url:http://sourceware.org/binutils/docs-2.20/as/
Gas的命令行参数:http://sourceware.org/binutils/docs-2.20/as/Invoking.html#Invoking

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
gcc编译c语言程序
使用GCC生成C语言和汇编混合的代码
gcc编译的四个阶段解析
c51 c和汇编语言混合编程
Linux下gcc与g++用法以及编写makefile
VC中生成汇编文件
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服