13 minute read

32비트 리눅스의 호출 규약Calling Convention에 대해서 알아보자.

  • 스택 메모리에서 서브루틴은 호출자의 아래쪽으로 생성된다.
  • eax 레지스터로 리턴값을 전달한다.
  • ebp 레지스터 위에 함수의 return address가 있고, 그 위에 인자argument가 쌓여있다.

int add(int a, int b){
    return a+b;
}

int main(){
    int a,b,c;
    a = 3;
    b = 7;
    c = add(a, b);
    return 0;
}

를 다음과 같이 32비트 컴파일을 하고 gdb로 확인해보자.

gcc -m32 add.c -o add
gdb add

add를 실행하는 과정을 쪼개서 과정을 표현해보았다(가로가 긴 화면에서 보는 것을 권장한다). 메모리를 한 열이 4바이트인 표로 그렸다. eip는 레지스터 표가 아닌 왼쪽에 어셈블리 코드에 화살표로 나타냈고, esp와 ebp는 메모리 표에 위치를 나타낼 수 있을 때 메모리에 표시했다.

(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
esp0xffffd4fc

Register Value
ebp0x0
(gdb) disass main
Dump of assembler code for function main:
-> 0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
esp0xffffd4f80x0

Register Value
ebp0x0
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
-> 0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
ebp,esp0xffffd4f80x0

Register Value
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
-> 0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
ebp0xffffd4f80x0
0xffffd4f4
0xffffd4f0
0xffffd4ec
esp0xffffd4e8

Register Value
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
-> 0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
ebp0xffffd4f80x0
0xffffd4f4
0xffffd4f0
0xffffd4ec0x3
esp0xffffd4e8

Register Value
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
-> 0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
ebp0xffffd4f80x0
0xffffd4f4
0xffffd4f00x7
0xffffd4ec0x3
esp0xffffd4e8

Register Value
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
-> 0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
ebp0xffffd4f80x0
0xffffd4f4
0xffffd4f00x7
0xffffd4ec0x3
0xffffd4e8
esp0xffffd4e40x7

Register Value
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
-> 0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
ebp0xffffd4f80x0
0xffffd4f4
0xffffd4f00x7
0xffffd4ec0x3
0xffffd4e8
0xffffd4e40x7
esp0xffffd4e00x3

Register Value
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
-> 0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
ebp0xffffd4f80x0
0xffffd4f4
0xffffd4f00x7
0xffffd4ec0x3
0xffffd4e8
0xffffd4e40x7
0xffffd4e00x3
esp0xffffd4dc0x08048417

Register Value
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
-> 0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
ebp0xffffd4f80x0
0xffffd4f4
0xffffd4f00x7
0xffffd4ec0x3
0xffffd4e8
0xffffd4e40x7
0xffffd4e00x3
0xffffd4dc0x08048417
esp0xffffd4d80xffffd4f8

Register Value
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
-> 0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
0xffffd4f80x0
0xffffd4f4
0xffffd4f00x7
0xffffd4ec0x3
0xffffd4e8
0xffffd4e40x7
0xffffd4e00x3
0xffffd4dc0x08048417
ebp,esp0xffffd4d80xffffd4f8

Register Value
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
-> 0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
0xffffd4f80x0
0xffffd4f4
0xffffd4f00x7
0xffffd4ec0x3
0xffffd4e8
0xffffd4e40x7
0xffffd4e00x3
0xffffd4dc0x08048417
ebp,esp0xffffd4d80xffffd4f8

Register Value
edx0x3
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
-> 0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
0xffffd4f80x0
0xffffd4f4
0xffffd4f00x7
0xffffd4ec0x3
0xffffd4e8
0xffffd4e40x7
0xffffd4e00x3
0xffffd4dc0x08048417
ebp,esp0xffffd4d80xffffd4f8

Register Value
edx0x3
eax0x7
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
-> 0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
0xffffd4f80x0
0xffffd4f4
0xffffd4f00x7
0xffffd4ec0x3
0xffffd4e8
0xffffd4e40x7
0xffffd4e00x3
0xffffd4dc0x08048417
ebp,esp0xffffd4d80xffffd4f8

Register Value
edx0x3
eax0xa
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
-> 0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
ebp0xffffd4f80x0
0xffffd4f4
0xffffd4f00x7
0xffffd4ec0x3
0xffffd4e8
0xffffd4e40x7
0xffffd4e00x3
esp0xffffd4dc0x08048417
0xffffd4d80xffffd4f8

Register Value
edx0x3
eax0xa
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
-> 0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
ebp0xffffd4f80x0
0xffffd4f4
0xffffd4f00x7
0xffffd4ec0x3
0xffffd4e8
0xffffd4e40x7
esp0xffffd4e00x3
0xffffd4dc0x08048417
0xffffd4d80xffffd4f8

Register Value
edx0x3
eax0xa
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
-> 0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
ebp0xffffd4f80x0
0xffffd4f4
0xffffd4f00x7
0xffffd4ec0x3
esp0xffffd4e8
0xffffd4e40x7
0xffffd4e00x3
0xffffd4dc0x08048417
0xffffd4d80xffffd4f8

Register Value
edx0x3
eax0xa
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
-> 0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
ebp0xffffd4f80x0
0xffffd4f40xa
0xffffd4f00x7
0xffffd4ec0x3
esp0xffffd4e8
0xffffd4e40x7
0xffffd4e00x3
0xffffd4dc0x08048417
0xffffd4d80xffffd4f8

Register Value
edx0x3
eax0xa
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
-> 0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
ebp0xffffd4f80x0
0xffffd4f40xa
0xffffd4f00x7
0xffffd4ec0x3
esp0xffffd4e8
0xffffd4e40x7
0xffffd4e00x3
0xffffd4dc0x08048417
0xffffd4d80xffffd4f8

Register Value
edx0x3
eax0x0
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
-> 0x08048422 <+42>:	leave  
   0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
0xffffd4fc
ebp,esp0xffffd4f80x0
0xffffd4f40xa
0xffffd4f00x7
0xffffd4ec0x3
0xffffd4e8
0xffffd4e40x7
0xffffd4e00x3
0xffffd4dc0x08048417
0xffffd4d80xffffd4f8

Register Value
edx0x3
eax0x0
(gdb) disass main
Dump of assembler code for function main:
   0x080483f8 <+0>:	push   %ebp
   0x080483f9 <+1>:	mov    %esp,%ebp
   0x080483fb <+3>:	sub    $0x10,%esp
   0x080483fe <+6>:	movl   $0x3,-0xc(%ebp)
   0x08048405 <+13>:	movl   $0x7,-0x8(%ebp)
   0x0804840c <+20>:	pushl  -0x8(%ebp)
   0x0804840f <+23>:	pushl  -0xc(%ebp)
   0x08048412 <+26>:	call   0x80483eb <add>
   0x08048417 <+31>:	add    $0x8,%esp
   0x0804841a <+34>:	mov    %eax,-0x4(%ebp)
   0x0804841d <+37>:	mov    $0x0,%eax
   0x08048422 <+42>:	leave  
-> 0x08048423 <+43>:	ret    
End of assembler dump.
(gdb) disass add
Dump of assembler code for function add:
   0x080483eb <+0>:	push   %ebp
   0x080483ec <+1>:	mov    %esp,%ebp
   0x080483ee <+3>:	mov    0x8(%ebp),%edx
   0x080483f1 <+6>:	mov    0xc(%ebp),%eax
   0x080483f4 <+9>:	add    %edx,%eax
   0x080483f6 <+11>:	pop    %ebp
   0x080483f7 <+12>:	ret    
End of assembler dump.
Address Value
esp0xffffd4fc
0xffffd4f80x0
0xffffd4f40xa
0xffffd4f00x7
0xffffd4ec0x3
0xffffd4e8
0xffffd4e40x7
0xffffd4e00x3
0xffffd4dc0x08048417
0xffffd4d80xffffd4f8

Register Value
edx0x3
eax0x0
ebp0x0

관련된 Assembly Instructions

  • push Reg: esp를 4 감소시키고 mov Reg, (%esp)한다.
  • pop Reg: mov (%esp), Reg 후 esp를 4 증가시킨다.
  • call Dest: push 다음 인스트럭션mov Dest, %eip한다.
  • ret: pop %eip
  • leave: mov %esp, %ebp

Categories:

Updated:

Leave a comment