对应上面的C代码,不难看出,和我们预想的完全一样,其中关键的地方我用不用的颜色标出来了,从汇编代码中我们同样可以看出,存放于栈中的局部数据其变量并没有出现在汇编代码中,是的,因为他直接存在了栈中,在程序中直接从栈中获得就没有必要用变量来访问了。
segment.out: file format elf32-i386
Disassembly of section .interp:
/*我们调用的函数放在这里*/
Disassembly of section .plt:
08048304 <__gmon_start__@plt-0x10>:
8048304: ff 35 80 97 04 08 pushl 0x8049780
804830a: ff 25 84 97 04 08 jmp *0x8049784
8048310: 00 00 add %al,(%eax)
...
08048314 <__gmon_start__@plt>:
8048314: ff 25 88 97 04 08 jmp *0x8049788
804831a: 68 00 00 00 00 push $0x0
804831f: e9 e0 ff ff ff jmp 8048304 <_init+0x30>
08048324 <__libc_start_main@plt>:
8048324: ff 25 8c 97 04 08 jmp *0x804978c
804832a: 68 08 00 00 00 push $0x8
804832f: e9 d0 ff ff ff jmp 8048304 <_init+0x30>
08048334 <printf@plt>:
8048334: ff 25 90 97 04 08 jmp *0x8049790
804833a: 68 10 00 00 00 push $0x10
804833f: e9 c0 ff ff ff jmp 8048304 <_init+0x30>
08048344 <malloc@plt>:
8048344: ff 25 94 97 04 08 jmp *0x8049794
804834a: 68 18 00 00 00 push $0x18
804834f: e9 b0 ff ff ff jmp 8048304 <_init+0x30>
08048354 <puts@plt>:
8048354: ff 25 98 97 04 08 jmp *0x8049798
804835a: 68 20 00 00 00 push $0x20
804835f: e9 a0 ff ff ff jmp 8048304 <_init+0x30>
/*.text段,这里放的是具体的代码*/
Disassembly of section .text:
08048370 <_start>:
...
08048424 <main>:
...
Disassembly of section .fini:
0804858c <_fini>:
...
/*.rodata区,存放只读数据*/
Disassembly of section .rodata:
080485a8 <_fp_hw>:
80485a8: 03 00 add (%eax),%eax
...
080485ac <_IO_stdin_used>:
80485ac: 01 00 add %eax,(%eax)
80485ae: 02 00 add (%eax),%al
080485b0 <__dso_handle>:
80485b0: 00 00 add %al,(%eax)
80485b2: 00 00 add %al,(%eax)
80485b4: 31 31 xor %esi,(%ecx)
80485b6: 31 31 xor %esi,(%ecx)
80485b8: 31 31 xor %esi,(%ecx)
80485ba: 31 31 xor %esi,(%ecx)
80485bc: 00 00 add %al,(%eax)
...
080485c0 <ci>:
80485c0: 09 00 or %eax,(%eax)
80485c2: 00 00 add %al,(%eax)
80485c4: 38 38 cmp %bh,(%eax)
80485c6: 38 38 cmp %bh,(%eax)
80485c8: 38 00 cmp %al,(%eax)
...
080485cc <cp>:
80485cc: c4 85 04 08 36 36 les 0x36360804(%ebp),%eax
80485d2: 36 36 36 00 38 add %bh,%ss:(%eax)
80485d7: 39 39 cmp %edi,(%ecx)
80485d9: 39 39 cmp %edi,(%ecx)
80485db: 00 61 5b add %ah,0x5b(%ecx)
80485de: 30 5d 3a xor %bl,0x3a(%ebp)
80485e1: 25 63 0a 70 5b and $0x5b700a63,%eax
80485e6: 30 5d 3a xor %bl,0x3a(%ebp)
80485e9: 25 63 0a 6c 61 and $0x616c0a63,%eax
80485ee: 5b pop %ebx
80485ef: 30 5d 3a xor %bl,0x3a(%ebp)
80485f2: 25 63 0a 6c 70 and $0x706c0a63,%eax
80485f7: 5b pop %ebx
80485f8: 30 5d 3a xor %bl,0x3a(%ebp)
80485fb: 25 63 0a 00 68 and $0x68000a63,%eax
8048600: 65 gs
8048601: 6c insb (%dx),%es:(%edi)
8048602: 6c insb (%dx),%es:(%edi)
8048603: 6f outsl %ds:(%esi),(%dx)
8048604: 20 77 6f and %dh,0x6f(%edi)
8048607: 72 6c jb 8048675 <scp.2177+0x61>
8048609: 64 00 6b 6b add %ch,%fs:0x6b(%ebx)
804860d: 6b 6b 6b 00 imul $0x0,0x6b(%ebx),%ebp
8048611: 00 00 add %al,(%eax)
...
08048614 <scp.2177>:
8048614: 0b .byte 0xb
8048615: 86 04 08 xchg %al,(%eax,%ecx,1)
Disassembly of section .eh_frame_hdr:
...
/*.data区,存放已初始化的全局和静态数据*/
Disassembly of section .data:
080497a0 <__data_start>:
...
080497c0 <a>:
80497c0: 32 32 xor (%edx),%dh
80497c2: 32 32 xor (%edx),%dh
80497c4: 32 32 xor (%edx),%dh
80497c6: 32 32 xor (%edx),%dh
...
08049824 <p>:
8049824: b4 85 mov $0x85,%ah
8049826: 04 08 add $0x8,%al
08049828 <sii.2174>:
8049828: 05 .byte 0x5
8049829: 00 00 add %al,(%eax)
...
/*.bss区,存放未初始化的全局和静态变量*/
Disassembly of section .bss:
08049840 <completed.5934>:
8049840: 00 00 add %al,(%eax)
...
08049844 <dtor_idx.5936>:
8049844: 00 00 add %al,(%eax)
...
08049848 <si.2173>:
...
08049860 <b>:
...
080499f0 <c>:
80499f0: 00 00 add %al,(%eax)
...
Disassembly of section .comment:
...
从不同颜色标出数据可以很清楚的看出,上面的的数据和前面我们分析的汇编代码完全一致。Windwos的情况类似,可以在工程->设置->C/C++分类中设置为Listing Files然后在列表中选择Assembly with Source Code,这样在debug或release文件夹下会生成C对应的汇编代码。当然也可以在调试的过程中直接看其每条C语句对应的汇编代码。
本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sky-heaven/p/5659512.html,如需转载请自行联系原作者