title: Assembly/ABI: Caller Responsibility for Large Return Types
body: <p>My assembly skills are rather poor, but I've been trying to understand assembly a little better to improve my understanding of profiling sessions and how optimizing compilers work.</p>
  
  <p>One of the things that I never stopped to really think about at the machine level when studying 64-bit calling conventions for Windows is that given something like this:</p>
  
  <pre><code>struct BigUdt
  {
      double buf[16]; // exceeds 64 bits
  };
  struct BigUdt create_big_udt();
  </code></pre>
  
  <p>... if I understood the documentation properly, <code>create_big_udt</code> would normally allocate the memory for <code>struct BigUdt</code> (I'm assuming on the stack) and return the address to its memory in <code>rax</code>.</p>
  
  <p>So my question, from an assembly standpoint, is this: <em>where does that leave the caller as far as responsibilities go?</em> I'm assuming someone is left with the responsibility of adding <code>sizeof(BidUdt)</code> back to <code>rsp</code> at some point. Also would 64-bit stack alignment become a concern here for types whose sizes aren't a multiple of 64-bits, or would that be covered by <code>struct BigUdt's</code> padding?</p>
  
  <p>Phew, I hope that's a reasonable question. I find these ABI contracts between caller and callee with calling conventions quite intimidating and one of the hardest parts of learning assembly so far.</p>