title: Understanding assembly recursive function
body: <p>I am learning assembly and I have this function that contains some lines I just don't understand:</p>
  
  <pre><code>. globl
  . text
  
  factR:
   cmpl $0 ,4(% esp )
   jne cont
   movl $1 ,%eax
   ret
  
  cont :
   movl 4(%esp),%eax
   decl %eax
   pushl %eax          // (1)
   call factR          // (2)
   addl $4,%esp        // (3)
   imull 4(%esp),%eax 
   ret
  </code></pre>
  
  <p>and the C code corresponding to it is:</p>
  
  <pre><code>int factR ( int n ) {
      if ( n != 0 )
          return n;
      else
          return n ∗ factR ( n − 1 );
  }
  </code></pre>
  
  <p>I am not sure about the lines marked with numbers.</p>
  
  <ol>
  <li><p><code>pushl %eax</code>: does it mean we put the contents of <code>%eax</code> in 
  <code>%esp</code>?</p></li>
  <li><p>So we call <code>factR()</code>. Will the result of that be in <code>%esp</code> when we come back here to the next instructions?</p></li>
  <li><p><code>addl $4,%esp</code> not sure about this one, are we adding 4 to the number stored in <code>%esp</code> or do we add 4 to the pointer to get the next number or something similar?</p></li>
  </ol>