title: Accessing stack frames in assembly language
body: <p>I am new to assembly and then I came across this <a href="http://en.wikibooks.org/wiki/X86_Disassembly/Functions_and_Stack_Frames" rel="nofollow">article</a> </p>
  
  <p>it says that this code </p>
  
  <pre><code>void MyFunction()
  {
    int a, b, c;
    a = 10;
    b = 5;
    c = 2;
  </code></pre>
  
  <p>is equivalent to this</p>
  
  <pre><code>push ebp     ; save the value of ebp
  mov ebp, esp ; ebp now points to the top of the stack
  sub esp, 12  ; space allocated on the stack for the local variables
  mov [ebp -  4], 10  ; location of variable a
  mov [ebp -  8], 5   ; location of b
  mov [ebp - 12], 2   ; location of c
  </code></pre>
  
  <p>According to this <a href="http://www.youtube.com/watch?v=vcfQVwtoyHY" rel="nofollow">video</a>, to access the value of the stack above the base pointer, we should add. If it is below the pointer, we should subtract. Given that example above, they subtracted something from the base pointer to move the location of variables needed, which is contrary to what is stated in the video. </p>
  
  <p>What did I miss? I know that sub esp, 12 is allocating a space for the local variables, so what I have in mind is that EBP is below that allocation, so I am thinking that it should be [ebp + something] not minus.</p>
  
  <p>So when he did this sub esp, 12, this is how the Stack looks like.</p>
  
  <pre><code>            ESP is here
  |     2    | Ebp + 12
  |     5    | Ebp + 8
  |     4    | Ebp + 4
  |          | Old EBP value
  </code></pre>
  
  <p>Was the article wrong, or I misinterpet it?</p>