I'd like to learn some assembly and now I have a question where ESP
shifts the intialized integer to during the function call of the main function.
The C-Code:
#include<stdio.h>
int main() {
int hallo = 5;
}
When I compile this file with GCC and decompile it with the command
objdump -M intel -D a.exe | grep -A20 main.
Then it looks like this:
00401460 <_main>:
401460: 55 push ebp
401461: 89 e5 mov ebp,esp
401463: 83 e4 f0 and esp,0xfffffff0
401466: 83 ec 10 sub esp,0x10
401469: e8 42 05 00 00 call 4019b0 <___main>
40146e: c7 44 24 0c 05 00 00 mov DWORD PTR [esp+0xc],0x5
401475: 00
401476: b8 00 00 00 00 mov eax,0x0
40147b: c9 leave
40147c: c3 ret
40147d: 90 nop
40147e: 90 nop
40147f: 90 nop
00401480 <__setargv>:
401480: 55 push ebp
401481: 89 e5 mov ebp,esp
401483: 57 push edi
401484: 56 push esi
401485: 53 push ebx
--
004019b0 <___main>:
4019b0: a1 28 70 40 00 mov eax,ds:0x407028
4019b5: 85 c0 test eax,eax
4019b7: 74 07 je 4019c0 <___main+0x10>
4019b9: f3 c3 repz ret
4019bb: 90 nop
4019bc: 8d 74 26 00 lea esi,[esi+eiz*1+0x0]
4019c0: c7 05 28 70 40 00 01 mov DWORD PTR ds:0x407028,0x1
4019c7: 00 00 00
4019ca: eb 94 jmp 401960 <___do_global_ctors>
4019cc: 90 nop
4019cd: 90 nop
4019ce: 90 nop
4019cf: 90 nop
004019d0 <.text>:
4019d0: 83 ec 1c sub esp,0x1c
4019d3: 8b 44 24 24 mov eax,DWORD PTR [esp+0x24]
4019d7: 83 f8 03 cmp eax,0x3
4019da: 74 14 je 4019f0 <.text+0x20>
4019dc: 85 c0 test eax,eax
I expect that the last assembly-command is mov DWORD PTR [esp+0xF],0x5
,
because the Stack is growing from top to bottom and because of Little Endian, the ESP must be positioned on [esp+0xF]
to fill up the next 4 Bytes (integer) to Position [esp+0xc]
.