I am learning assembly and I have this assembly code and having much trouble understanding it can someone clarify it?
Dump of assembler code for function main:
0x080483ed <+0>: push ebp
0x080483ee <+1>: mov ebp,esp
0x080483f0 <+3>: sub esp,0x10
0x080483f3 <+6>: mov DWORD PTR [ebp-0x8],0x0
0x080483fa <+13>: mov eax,DWORD PTR [ebp-0x8]
0x080483fd <+16>: add eax,0x1
0x08048400 <+19>: mov DWORD PTR [ebp-0x4],eax
0x08048403 <+22>: leave
0x08048404 <+23>: ret
Until now, my understood knowledge is the following:
Push something (don't know what) in ebp
register. then move content of esp
register into ebp
(I think the data of ebp
should be overwritten), then subtract 10 from the esp
and store it in the esp
(The function will take 10 byte, This reg is never used again, so no point of doing this operation). Now assign value 0 to the address pointed by 8 bytes less than ebp
.
Now store that address into register eax
. Now add 1 to the value pointed by eax
(the previous value is lost). Now store the eax
value on [ebp-0x4]
, then leave to the return address of main
.
Here is my C code for the above program:
int main(){
int x=0;
int y = x+1;
}
Now, can someone figure out if I am wrong at anything,and I also don't understand the mov
at <+13> it adds 1 to the addrs ebp-0x8
, but that is the address of int x
so, x
no longer contain 0. Where am I wrong?