title: Assembly x86 what's the purpose of "enter 0,0"
body: <p>At the moment I am learning assembly for x86 with NASM. I tried to write the following function who is calculating the fibonacci numbers:</p>
  
  <pre><code>unsigned int fibonacci(unsigned int n) {
      if (n &lt; 2)
          return 1;
      else
          return fibonacci(n - 1) + fibonacci(n - 2);
  }
  </code></pre>
  
  <p>This is what I did so far, and it works great, exactly like the above method. But as I understand the <code>enter 0,0</code> instruction is there to free up space in the stack for local variables. I push two local variables to the stack: <code>push dword ptr[n]</code>. But shouldn't this only be possible if I use the <code>enter</code> instruction like this: <code>enter 8,0</code>. To free up space for the two int variables. If I try to do so, I get a StackOverflow exception. </p>
  
  <pre><code>__declspec(naked) unsigned int fibonacci2(unsigned int n) {
      __asm {
          enter 0,0
          cmp dword ptr [n], 2
          jae elsee
          mov eax, 1
          jmp end
          elsee:
          push dword ptr[n] // Here I am pushing two local variables to the stack.
          push dword ptr[n] // 2 * 4 Bytes
          dec [ebp-4]
          dec [ebp-8]
          dec [ebp-8]
          push[ebp-4]
          call fibonacci2     
          mov [ebp-4], eax
          push [ebp-8]
          call fibonacci2
          add eax, [ebp-4]
          end:
          leave
          ret
      }
   }
  </code></pre>
  
  <p>This is the compiled version of the function: </p>
  
  <pre><code>00C426E0  enter       0,0  
  00C426E4  cmp         dword ptr [n],2  
  00C426E8  jae         fibonacci2+11h (0C426F1h)  
  00C426EA  mov         eax,1  
  00C426EF  jmp         end (0C42716h)  
  elsee:
  00C426F1  push        dword ptr [n]  
  00C426F4  push        dword ptr [n]  
  00C426F7  dec         byte ptr [ebp-4]  
  00C426FA  dec         byte ptr [ebp-8]  
  00C426FD  dec         byte ptr [ebp-8]  
  00C42700  push        dword ptr [ebp-4]  
  00C42703  call        _fibonacci2 (0C413BBh)  
  00C42708  mov         dword ptr [ebp-4],eax  
  00C4270B  push        dword ptr [ebp-8]  
  00C4270E  call        _fibonacci2 (0C413BBh)  
  00C42713  add         eax,dword ptr [ebp-4]  
  end:
  00C42716  leave  
  00C42717  ret
  </code></pre>