title: Save variable to stack (X86-64 assembly)
body: <p>I've written a small program in x86-64 assembly (AT&amp;T) syntax, and it assembles just fine, but I don't get the result I expected.
  I have a variable in register <code>%rdi</code>, which I need to modify in a subroutine, and I need to keep the original value for some other usage later. What I want to do is to <code>push</code> the original value onto the stack, and then retrieve it again when the subroutine finishes, for example, if the variable is located in <code>%rdi</code>.</p>
  
  <pre><code>    pushq %rdi
      call subroutine
      movq (%rsp), %rdi
  </code></pre>
  
  <p>Now, I'm not really sure if this is the correct way to do it? I've read somewhere that a subroutine pushes the return value onto of the stack, but does that mean that I have to include an offset when I try to retrieve the variable?</p>
  
  <p>Also I know I have to keep the stack pointer aligned by 16 bytes, which I'm not quite sure if I do. In case I don't, will the assembler then give me an error, or could that be the reason why my program fails?</p>
  
  <p>And by the way, this program is part of an assignment, so I cannot share the code with you, but I hope my description is good enough.</p>