title: Does pushl %esp update ESP before or after storing?
body: <p>The <code>pushl</code> Y86 instruction both decrements the stack pointer by 4 and writes a register value to memory. So it's not clear what the processor should do when it executes the instruction <code>pushl %esp</code>, since the register being pushed is being changed by the same instruction. Two possible events can occur:</p>
  
  <p>(1) push the original value of <code>%esp</code>, or (2) push the decremented value of <code>%esp</code>.</p>
  
  <p>In light of this, how could we modify this code-equivalent of <code>pushl REG</code> to account for, and accomdate, these ambiguities (being that REG can be %esp as well as any other register)?:</p>
  
  <pre><code>subl $4,%esp                   Decrement stack pointer
  movl REG,(%esp)                Store REG on stack
  </code></pre>
  
  <hr>
  
  <p>Similarly, the instruction <code>popl %esp</code> could either set <code>%esp</code> to the value read from memory or to the incremented stack pointer. How could this code be changed to accommodate for these ambiguities?:</p>
  
  <pre><code>movl (%esp),REG                Read REG from stack
  addl $4,%esp                   Increment stack pointer
  </code></pre>