title: lodsd / stosd assembly instructions : possible errata in reversing book
body: <p>In page 25 of "Practical Reverse Engineering  x86 - x64 ARM, Kernel &amp; Obfuscation" I found an assembly code example retranslated to rough C in which lodsd and stosd instructions "translations" seems inverted. Since I'm fairy new to assembly language I'd like to know if it's really an errata or there's something more under the hood that I'm possibly not taking in count.
  Here's the simple code :</p>
  
  <p><b>Assembly</b></p>
  
  <pre><code>01: 8B CA     mov ecx, edx
  02:           loc_CFB8F:
  03: AD        lodsd
  04: F7 D0     not eax
  05: AB        stosd
  06: E2 FA     loop loc_CFB8F
  </code></pre>
  
  <p><b>Rough C</b></p>
  
  <pre><code>while (ecx != 0) {
  eax = *edi;
  edi++;
  *esi = ~eax;
  esi++;
  ecx--;
  }
  </code></pre>
  
  <p>In every online explanation I read about lods instruction, it's stated that whatever value is in SI/ESI is stored in AL/AX/EAX and then increments ESI.</p>
  
  <p>Similiarly, stos should represent a rough high level "memset" in which whatever sits in AL/AX/EAX is written to DI/EDI and then increments the register.</p>
  
  <p>But it appears i'm wrong since in the above translation eax gets assigned the dereference of EDI instead of ESI, and right below the value pointed by ESI gets the inverted eax with stos. Am I missing something here ?</p>