title: Fastest way to set a single memory cell to zero or a constant in x86 assembly?
body: <p>What is the fastest way to set a single memory cell to zero in x86? Typically the way I do it is this:</p>
  
  <pre><code>C745D800000000  MOV [ebp-28], 0
  </code></pre>
  
  <p>As you can see this has a pretty chunky encoding since it is using all 4 bytes for the constant. With a plain register I can use <code>MVZE</code> which is more compact, but <code>MVZE</code> does not work with memory.</p>
  
  <p>I was thinking maybe clear a register, then <code>MOV</code> the register value to the memory. Then, it would be two instructions, but only 5 bytes total instead of the one 7-byte instruction above. Following the rule "if its shorter, its usually faster", this might be preferable.</p>