How come the following x86_64 assembly gives me a segmentation fault?
<p>So far I've been learning to write some x86_64 assembly. I read that you can subtract the RSP to grow the stack downwards and allocate space, so I wrote the following code:</p>

<pre><code>push %rbp
movq %rsp, %rbp
subq $16, %rsp
movq $200, -8(%rsp)
movq $300, -16(%rsp)
popq %rbp
retq
</code></pre>

<p>From my understanding, this will make a function where it sets up a the stack frame, then it allocates 16 bytes on the stack and sets the values at -8 and -16 to 200 and 300 respectively.
However, when I run this with gcc, I get a segmentation fault. Though if I remove the <code>sub</code> part of the program, it works perfectly. I assume I've misunderstood something, so what is actually going on here?</p>