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