title: x86 mov / add Instructions & Memory Addressing
body: <p>I'm learning x86 assembly in class and I'm very lost as to how you differentiate between what a register operand and what a memory reference does. I had several confusions I was hoping to clear up. </p>
  
  <p>The following code is what my textbook says is the long way to do push and pop respectively:</p>
  
  <pre><code>subl $4, %esp
  movl %ebp, (%esp)
  
  movl (%esp), %eax
  addl $4, %esp
  </code></pre>
  
  <p>So in the subl instruction, can we always expect %esp to hold an address value?</p>
  
  <p>Also what is the difference between the two movl functions? Can the first one be written as </p>
  
  <pre><code>movl (%ebp), %esp
  </code></pre>
  
  <p>? And for the second movl, does that move the address of %esp or does it move the value pointed to by %esp?</p>
  
  <p>As a follow-up then, why can't we have the source and destination be memory references like so?</p>
  
  <pre><code>movw (%eax), 4(%esp)
  </code></pre>
  
  <p>And lastly, for the following code:</p>
  
  <pre><code>movb (%esp, %edx, 4), %dh
  </code></pre>
  
  <p>if the source is more than 1 byte (the size of %dh), then what happens? Does it just truncate the value? </p>
  
  <p>Sorry, this was a ton of questions but any help would be greatly appreciated. </p>