title: Understanding C program in Assembly
body: <p>I'm trying to understand this simple C program:</p>
  
  <pre><code>int square(int num) {
      return num * num; 
  }
  </code></pre>
  
  <p>When it's in Assembly code:</p>
  
  <pre><code>square(int): 
    push rbp ;push rbp register onto stack
    mov rbp, rsp ;move contents of rbp register into rsp register 
    mov DWORD PTR [rbp-4], edi ;not sure what happens here 
    mov eax, DWORD PTR [rbp-4] ;not sure what happens here
    imul eax, DWORD PTR [rbp-4] ;multiply eax and DWORD PTR [rbp-4] (?)
    pop rbp ;pop original register out of stack
    ret ;return 
  </code></pre>
  
  <ol>
  <li>What is happening in the 3rd and 4th line?</li>
  <li>Why did two more register (edi and eax) have to be used instead of rsp?</li>
  <li>What is actually happening with DWORD PTR [rbp-4]? </li>
  </ol>