title: REPNZ SCAS Assembly Instruction Specifics
body: <p>I am trying to reverse engineer a binary and the following instruction is confusing me, can anyone clarify what exactly this does?</p>
  
  <pre><code>=&gt;0x804854e:    repnz scas al,BYTE PTR es:[edi]
    0x8048550:    not    ecx
  </code></pre>
  
  <p>Where:</p>
  
  <pre><code>EAX: 0x0
  ECX: 0xffffffff
  EDI: 0xbffff3dc ("aaaaaa\n")
  ZF:  1
  </code></pre>
  
  <p>I see that it is somehow decrementing ECX by 1 each iteration, and that EDI is incrementing along the length of the string.  I know it calculates the length of the string, but as far as exactly HOW it's happening, and why "al" is involved I'm not quite sure.</p>