title: What are the location of the following arguments in the stack assemblyx86
body: <p>For this assume that we are using Windows (so that the first 5 arguments of a function are in registers and the rest are pushed on the stack in reverse order)</p>
  <p>Consider the following function:</p>
  <pre><code>// int foo(int a, int b, int c, int d, int e, int f, int g, int h, int i)
      // {
      //   int x, y, z;
      //   x = g+1;
      //   y = h+1;
      //   z = i+1;
      // return x+y+z;
      // }
  </code></pre>
  <p>on assembly the function starts like this:</p>
  <pre><code>foo: 
  pushq   %rbp 
  movq    %rsp, %rbp
  
  subq    $32,%rsp    #allocate space for %rbx plus three 4-byte local variables, keeping 16-byte alignment
   ...
  </code></pre>
  <p>(%rbx is a callee register and will be pushed into the stack so we allocate more space by decrementing %rsp)</p>
  <p>My question is given this information? what are the location (as offsets of %rbp) of ints e,f,g,h,i</p>
  <p>According to my professor:</p>
  <pre><code># e is at %rbp + 48   (unused in this function) 
  # f is at %rbp + 56   (unused in this function)
  # g is at %rbp + 64      
  # h is at %rbp + 72
  # i is at %rbp + 80
  </code></pre>
  <p>But I don't really understand the logic.</p>
  <p>To me, it feels like here there is some confusion between %rsp and %rbp.<br />
  In my opinion the stack looks more like this:</p>
  <p><a href="https://i.stack.imgur.com/hBu26.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hBu26.png" alt="stack" /></a></p>
  <p>(the addresses as offsets of %rbp are on the picture)</p>
  <p>Am I missing something?</p>