디스어셈블, gcc보다는 objdump가 나은듯 하다.
결론부터 말하면, 컴파일된 오브젝트 파일( *.o )을 objdump로 보는게 gcc의 옵션을 통해 출력하는 것보다 낫다는 것이다.
gcc의 출력은 일단 좀 산만하기도 하고, C++ 코드와 어셈블리 루틴이 정확히 매치되지 않아서 좀 보기가 힘들다.
아래의 예를 보면, C++ 구문 아래에 번역된 어셈블리 결과가 매치되어 보이는 걸 알 수 있다.
-Mintel 옵션을 붙이면, 인텔 문법의 어셈블리가 나오고,
-C 옵션을 붙이면, 함수 이름이 demangle되서 우리가 알아볼 수 있게 나온다.
하지만 인라인 함수 알아보기 힘든건 여전함.
ps. gcc로 컴파일할 때, -g 옵션을 붙여 디버깅 정보를 넘겨줘야 한다. 안그러면 C++코드가 안나오네.
complex.o: file format pe-i386
Disassembly of section .text:
00000000 <main>:
#include "complex.h"
int main(int argc, char *argv[])
{
0: 55 push ebp
1: 89 e5 mov ebp,esp
3: 57 push edi
4: 56 push esi
5: 53 push ebx
6: 81 ec 9c 00 00 00 sub esp,0x9c
c: 83 e4 f0 and esp,0xfffffff0
f: b8 00 00 00 00 mov eax,0x0
14: 83 c0 0f add eax,0xf
17: 83 c0 0f add eax,0xf
1a: c1 e8 04 shr eax,0x4
1d: c1 e0 04 shl eax,0x4
20: 89 85 74 ff ff ff mov DWORD PTR [ebp-140],eax
26: 8b 85 74 ff ff ff mov eax,DWORD PTR [ebp-140]
2c: e8 00 00 00 00 call 31 <main+0x31>
31: c7 45 9c 00 00 00 00 mov DWORD PTR [ebp-100],0x0
38: c7 45 a0 00 00 00 00 mov DWORD PTR [ebp-96],0x0
3f: 8d 45 a4 lea eax,[ebp-92]
42: 8d 55 e8 lea edx,[ebp-24]
45: 89 10 mov DWORD PTR [eax],edx
47: ba e6 00 00 00 mov edx,0xe6
4c: 89 50 04 mov DWORD PTR [eax+4],edx
4f: 89 60 08 mov DWORD PTR [eax+8],esp
52: 8d 45 84 lea eax,[ebp-124]
55: 89 04 24 mov DWORD PTR [esp],eax
58: e8 00 00 00 00 call 5d <main+0x5d>
5d: e8 00 00 00 00 call 62 <main+0x62>
float r;
float i;
public:
macro Complex(){}
62: 8d 45 d8 lea eax,[ebp-40]
65: 89 45 d4 mov DWORD PTR [ebp-44],eax
68: 8d 45 b8 lea eax,[ebp-72]
6b: 89 45 d4 mov DWORD PTR [ebp-44],eax
int main(int argc, char *argv[])
{
Complex a, b;
a(.5,.5);
6e: b8 00 00 00 3f mov eax,0x3f000000
73: 89 44 24 08 mov DWORD PTR [esp+8],eax
77: b8 00 00 00 3f mov eax,0x3f000000
7c: 89 44 24 04 mov DWORD PTR [esp+4],eax
80: 8d 45 d8 lea eax,[ebp-40]
83: 89 04 24 mov DWORD PTR [esp],eax
86: e8 00 00 00 00 call 8b <main+0x8b>
b(.3,.4);
8b: b8 cd cc cc 3e mov eax,0x3ecccccd
90: 89 44 24 08 mov DWORD PTR [esp+8],eax
94: b8 9a 99 99 3e mov eax,0x3e99999a
99: 89 44 24 04 mov DWORD PTR [esp+4],eax
9d: 8d 45 b8 lea eax,[ebp-72]
a0: 89 04 24 mov DWORD PTR [esp],eax
a3: e8 00 00 00 00 call a8 <main+0xa8>
a.print();
a8: 8d 45 d8 lea eax,[ebp-40]
ab: 89 04 24 mov DWORD PTR [esp],eax
ae: c7 45 88 01 00 00 00 mov DWORD PTR [ebp-120],0x1
b5: e8 00 00 00 00 call ba <main+0xba>
b.print();
ba: 8d 45 b8 lea eax,[ebp-72]
bd: 89 04 24 mov DWORD PTR [esp],eax
c0: e8 00 00 00 00 call c5 <main+0xc5>
system("PAUSE");
c5: c7 04 24 00 00 00 00 mov DWORD PTR [esp],0x0
cc: e8 00 00 00 00 call d1 <main+0xd1>
return EXIT_SUCCESS;
d1: 8d 45 b8 lea eax,[ebp-72]
d4: 89 45 d4 mov DWORD PTR [ebp-44],eax
d7: 8d 45 d8 lea eax,[ebp-40]
da: 89 45 d4 mov DWORD PTR [ebp-44],eax
dd: c7 45 80 00 00 00 00 mov DWORD PTR [ebp-128],0x0
e4: eb 45 jmp 12b <main+0x12b>
e6: 8d 6d 18 lea ebp,[ebp+24]
e9: 8b 45 8c mov eax,DWORD PTR [ebp-116]
ec: 89 85 7c ff ff ff mov DWORD PTR [ebp-132],eax
f2: 8b 95 7c ff ff ff mov edx,DWORD PTR [ebp-132]
float i;
public:
macro Complex(){}
macro ~Complex(){}
f8: 8d 45 b8 lea eax,[ebp-72]
fb: 89 45 d4 mov DWORD PTR [ebp-44],eax
fe: 89 95 7c ff ff ff mov DWORD PTR [ebp-132],edx
104: 8b 95 7c ff ff ff mov edx,DWORD PTR [ebp-132]
10a: 8d 45 d8 lea eax,[ebp-40]
10d: 89 45 d4 mov DWORD PTR [ebp-44],eax
110: 89 95 7c ff ff ff mov DWORD PTR [ebp-132],edx
116: 8b 95 7c ff ff ff mov edx,DWORD PTR [ebp-132]
11c: 89 14 24 mov DWORD PTR [esp],edx
11f: c7 45 88 ff ff ff ff mov DWORD PTR [ebp-120],0xffffffff
126: e8 00 00 00 00 call 12b <main+0x12b>
12b: 8d 45 84 lea eax,[ebp-124]
12e: 89 04 24 mov DWORD PTR [esp],eax
131: e8 00 00 00 00 call 136 <main+0x136>
}
136: 8b 45 80 mov eax,DWORD PTR [ebp-128]
139: 8d 65 f4 lea esp,[ebp-12]
13c: 5b pop ebx
13d: 5e pop esi
13e: 5f pop edi
13f: 5d pop ebp
140: c3 ret
141: 90 nop
142: 90 nop
143: 90 nop
144: 90 nop
145: 90 nop
146: 90 nop
147: 90 nop
148: 90 nop
149: 90 nop
14a: 90 nop
14b: 90 nop
14c: 90 nop
14d: 90 nop
14e: 90 nop
14f: 90 nop
Disassembly of section .text$_ZN7Complex5printEv:
00000000 <Complex::print()>:
0: 55 push ebp
1: 89 e5 mov ebp,esp
3: 83 ec 18 sub esp,0x18
6: 8b 45 08 mov eax,DWORD PTR [ebp+8]
9: d9 40 04 fld DWORD PTR [eax+4]
c: dd 5c 24 0c fstp QWORD PTR [esp+12]
10: 8b 45 08 mov eax,DWORD PTR [ebp+8]
13: d9 00 fld DWORD PTR [eax]
15: dd 5c 24 04 fstp QWORD PTR [esp+4]
19: c7 04 24 06 00 00 00 mov DWORD PTR [esp],0x6
20: e8 00 00 00 00 call 25 <Complex::print()+0x25>
25: c9 leave
26: c3 ret
27: 90 nop
Disassembly of section .text$_ZN7ComplexclEff:
00000000 <Complex::operator()(float, float)>:
0: 55 push ebp
1: 89 e5 mov ebp,esp
3: 8b 55 08 mov edx,DWORD PTR [ebp+8]
6: 8b 45 0c mov eax,DWORD PTR [ebp+12]
9: 89 02 mov DWORD PTR [edx],eax
b: 8b 55 08 mov edx,DWORD PTR [ebp+8]
e: 8b 45 10 mov eax,DWORD PTR [ebp+16]
11: 89 42 04 mov DWORD PTR [edx+4],eax
14: 5d pop ebp
15: c3 ret
16: 90 nop
17: 90 nop
complex.o: file format pe-i386
Disassembly of section .text:
00000000 <_main>:
#include "complex.h"
int main(int argc, char *argv[])
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 57 push %edi
4: 56 push %esi
5: 53 push %ebx
6: 81 ec 9c 00 00 00 sub $0x9c,%esp
c: 83 e4 f0 and $0xfffffff0,%esp
f: b8 00 00 00 00 mov $0x0,%eax
14: 83 c0 0f add $0xf,%eax
17: 83 c0 0f add $0xf,%eax
1a: c1 e8 04 shr $0x4,%eax
1d: c1 e0 04 shl $0x4,%eax
20: 89 85 74 ff ff ff mov %eax,0xffffff74(%ebp)
26: 8b 85 74 ff ff ff mov 0xffffff74(%ebp),%eax
2c: e8 00 00 00 00 call 31 <_main+0x31>
31: c7 45 9c 00 00 00 00 movl $0x0,0xffffff9c(%ebp)
38: c7 45 a0 00 00 00 00 movl $0x0,0xffffffa0(%ebp)
3f: 8d 45 a4 lea 0xffffffa4(%ebp),%eax
42: 8d 55 e8 lea 0xffffffe8(%ebp),%edx
45: 89 10 mov %edx,(%eax)
47: ba e6 00 00 00 mov $0xe6,%edx
4c: 89 50 04 mov %edx,0x4(%eax)
4f: 89 60 08 mov %esp,0x8(%eax)
52: 8d 45 84 lea 0xffffff84(%ebp),%eax
55: 89 04 24 mov %eax,(%esp)
58: e8 00 00 00 00 call 5d <_main+0x5d>
5d: e8 00 00 00 00 call 62 <_main+0x62>
float r;
float i;
public:
macro Complex(){}
62: 8d 45 d8 lea 0xffffffd8(%ebp),%eax
65: 89 45 d4 mov %eax,0xffffffd4(%ebp)
68: 8d 45 b8 lea 0xffffffb8(%ebp),%eax
6b: 89 45 d4 mov %eax,0xffffffd4(%ebp)
Complex a, b;
a(.5,.5);
6e: b8 00 00 00 3f mov $0x3f000000,%eax
73: 89 44 24 08 mov %eax,0x8(%esp)
77: b8 00 00 00 3f mov $0x3f000000,%eax
7c: 89 44 24 04 mov %eax,0x4(%esp)
80: 8d 45 d8 lea 0xffffffd8(%ebp),%eax
83: 89 04 24 mov %eax,(%esp)
86: e8 00 00 00 00 call 8b <_main+0x8b>
b(.3,.4);
8b: b8 cd cc cc 3e mov $0x3ecccccd,%eax
90: 89 44 24 08 mov %eax,0x8(%esp)
94: b8 9a 99 99 3e mov $0x3e99999a,%eax
99: 89 44 24 04 mov %eax,0x4(%esp)
9d: 8d 45 b8 lea 0xffffffb8(%ebp),%eax
a0: 89 04 24 mov %eax,(%esp)
a3: e8 00 00 00 00 call a8 <_main+0xa8>
a.print();
a8: 8d 45 d8 lea 0xffffffd8(%ebp),%eax
ab: 89 04 24 mov %eax,(%esp)
ae: c7 45 88 01 00 00 00 movl $0x1,0xffffff88(%ebp)
b5: e8 00 00 00 00 call ba <_main+0xba>
b.print();
ba: 8d 45 b8 lea 0xffffffb8(%ebp),%eax
bd: 89 04 24 mov %eax,(%esp)
c0: e8 00 00 00 00 call c5 <_main+0xc5>
system("PAUSE");
c5: c7 04 24 00 00 00 00 movl $0x0,(%esp)
cc: e8 00 00 00 00 call d1 <_main+0xd1>
return EXIT_SUCCESS;
d1: 8d 45 b8 lea 0xffffffb8(%ebp),%eax
d4: 89 45 d4 mov %eax,0xffffffd4(%ebp)
d7: 8d 45 d8 lea 0xffffffd8(%ebp),%eax
da: 89 45 d4 mov %eax,0xffffffd4(%ebp)
dd: c7 45 80 00 00 00 00 movl $0x0,0xffffff80(%ebp)
e4: eb 45 jmp 12b <_main+0x12b>
e6: 8d 6d 18 lea 0x18(%ebp),%ebp
e9: 8b 45 8c mov 0xffffff8c(%ebp),%eax
ec: 89 85 7c ff ff ff mov %eax,0xffffff7c(%ebp)
f2: 8b 95 7c ff ff ff mov 0xffffff7c(%ebp),%edx
float i;
public:
macro Complex(){}
macro ~Complex(){}
f8: 8d 45 b8 lea 0xffffffb8(%ebp),%eax
fb: 89 45 d4 mov %eax,0xffffffd4(%ebp)
fe: 89 95 7c ff ff ff mov %edx,0xffffff7c(%ebp)
104: 8b 95 7c ff ff ff mov 0xffffff7c(%ebp),%edx
10a: 8d 45 d8 lea 0xffffffd8(%ebp),%eax
10d: 89 45 d4 mov %eax,0xffffffd4(%ebp)
110: 89 95 7c ff ff ff mov %edx,0xffffff7c(%ebp)
116: 8b 95 7c ff ff ff mov 0xffffff7c(%ebp),%edx
11c: 89 14 24 mov %edx,(%esp)
11f: c7 45 88 ff ff ff ff movl $0xffffffff,0xffffff88(%ebp)
126: e8 00 00 00 00 call 12b <_main+0x12b>
12b: 8d 45 84 lea 0xffffff84(%ebp),%eax
12e: 89 04 24 mov %eax,(%esp)
131: e8 00 00 00 00 call 136 <_main+0x136>
}
136: 8b 45 80 mov 0xffffff80(%ebp),%eax
139: 8d 65 f4 lea 0xfffffff4(%ebp),%esp
13c: 5b pop %ebx
13d: 5e pop %esi
13e: 5f pop %edi
13f: 5d pop %ebp
140: c3 ret
141: 90 nop
142: 90 nop
143: 90 nop
144: 90 nop
145: 90 nop
146: 90 nop
147: 90 nop
148: 90 nop
149: 90 nop
14a: 90 nop
14b: 90 nop
14c: 90 nop
14d: 90 nop
14e: 90 nop
14f: 90 nop
Disassembly of section .text$_ZN7Complex5printEv:
00000000 <__ZN7Complex5printEv>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 ec 18 sub $0x18,%esp
6: 8b 45 08 mov 0x8(%ebp),%eax
9: d9 40 04 flds 0x4(%eax)
c: dd 5c 24 0c fstpl 0xc(%esp)
10: 8b 45 08 mov 0x8(%ebp),%eax
13: d9 00 flds (%eax)
15: dd 5c 24 04 fstpl 0x4(%esp)
19: c7 04 24 06 00 00 00 movl $0x6,(%esp)
20: e8 00 00 00 00 call 25 <__ZN7Complex5printEv+0x25>
25: c9 leave
26: c3 ret
27: 90 nop
Disassembly of section .text$_ZN7ComplexclEff:
00000000 <__ZN7ComplexclEff>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 8b 55 08 mov 0x8(%ebp),%edx
6: 8b 45 0c mov 0xc(%ebp),%eax
9: 89 02 mov %eax,(%edx)
b: 8b 55 08 mov 0x8(%ebp),%edx
e: 8b 45 10 mov 0x10(%ebp),%eax
11: 89 42 04 mov %eax,0x4(%edx)
14: 5d pop %ebp
15: c3 ret
16: 90 nop
17: 90 nop