用GCC輸出帶C原始碼注釋的彙編列表檔案

來源:互聯網
上載者:User

 

我們都知道gcc的-S開關可以用來產生彙編代碼,

但有時候,單有彙編檔案是不夠的,我們希望的是將C語言程式的原始碼和組合語言文本交錯在一起查看,

這是LISTING功能,在gcc中並沒有專門的FAQ說明,

區區在網上查了很多資料才知道怎麼實現,所以特此記下。

 

gcc -c -g -Wa,-adlhn ee.c >  ee.anno.s

 

由此產生的ee.anno.s即是ee.c對應的C與彙編混排的列表

 


又如C程式

 

/* EE */

#include<stdio.h>

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

#include<windows.h>

int main(int argc, char **argv)

{

  char * p = "TO STDOUT";

  int ic   = (int)GetStdHandle(STD_OUTPUT_HANDLE);

  printf("%d/n", ic);

  WriteFile(ic, p, strlen(p), &ic, NULL);

 

  return 0;

}

 

可以產生
   1              
.file
"ee.c"   4              
.text   5              
Ltext0: 4222              
.section .rdata,"dr" 4223              
LC0: 4224 0000 544F2053
.ascii "TO STDOUT/0" 4224      54444F55  4224      5400 4225              
LC1: 4226 000a 25640A00
.ascii "%d/12/0" 4227 000e 0000    
.text 4231              
.globl _main 4233              
_main:   1:ee.c          **** /* EE */   2:ee.c          **** #include<stdio.h>   3:ee.c          **** #include<stdio.h>   4:ee.c          **** #include<string.h>   5:ee.c          **** #include<stdlib.h>   6:ee.c          **** #include<windows.h>   7:ee.c          **** int main(int argc, char **argv)   8:ee.c          **** { 4235              
LM1: 4236 0000 55      
pushl
%ebp 4237 0001 89E5    
movl
%esp, %ebp 4238 0003 83EC28  
subl
$40, %esp 4239 0006 83E4F0  
andl
$-16, %esp 4240 0009 B8000000
movl
$0, %eax 4240      00 4241 000e 83C00F  
addl
$15, %eax 4242 0011 83C00F  
addl
$15, %eax 4243 0014 C1E804  
shrl
$4, %eax 4244 0017 C1E004  
sall
$4, %eax 4245 001a 8945F4  
movl
%eax, -12(%ebp) 4246 001d 8B45F4  
movl
-12(%ebp), %eax 4247 0020 E8000000
call
__alloca 4247      00 4249              
LM2: 4250 0025 E8000000
call
___main 4250      00   9:ee.c          ****   char * p = "TO STDOUT"; 4252              
LM3: 4253 002a C745FC00
movl
$LC0, -4(%ebp) 4253      000000  10:ee.c          ****   int ic   = (int)GetStdHandle(STD_OUTPUT_HANDLE); 4255              
LM4: 4256 0031 C70424F5
movl
$-11, (%esp) 4256      FFFFFF 4257 0038 E8000000
call
_GetStdHandle@4 4257      00 4258 003d 83EC04  
subl
$4, %esp 4259 0040 8945F8  
movl
%eax, -8(%ebp)  11:ee.c          ****   printf("%d/n", ic); 4261              
LM5: 4262 0043 8B45F8  
movl
-8(%ebp), %eax 4263 0046 89442404
movl
%eax, 4(%esp) 4264 004a C704240A
movl
$LC1, (%esp) 4264      000000 4265 0051 E8000000
call
_printf 4265      00  12:ee.c          ****   WriteFile(ic, p, strlen(p), &ic, NULL); 4267              
LM6: 4268 0056 8B45FC  
movl
-4(%ebp), %eax 4269 0059 890424  
movl
%eax, (%esp) 4270 005c E8000000
call
_strlen 4270      00 4271 0061 89C2    
movl
%eax, %edx 4272 0063 C7442410
movl
$0, 16(%esp) 4272      00000000  4273 006b 8D45F8  
leal
-8(%ebp), %eax 4274 006e 8944240C
movl
%eax, 12(%esp) 4275 0072 89542408
movl
%edx, 8(%esp) 4276 0076 8B45FC  
movl
-4(%ebp), %eax 4277 0079 89442404
movl
%eax, 4(%esp) 4278 007d 8B45F8  
movl
-8(%ebp), %eax 4279 0080 890424  
movl
%eax, (%esp) 4280 0083 E8000000
call
_WriteFile@20 4280      00 4281 0088 83EC14  
subl
$20, %esp  13:ee.c          ****     14:ee.c          ****   return 0; 4283              
LM7: 4284 008b B8000000
movl
$0, %eax 4284      00  15:ee.c          **** } 4286              
LM8: 4287 0090 C9      
leave 4288 0091 C3      
ret 4293              
Lscope0: 4295              
.text 4297              
Letext:
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.