title: Assembly x86: splitting string based on delimiter
body: <p>Goal: Take string 'One Two Three' which is stored in EDI and call strtok. 
  strtok should split the string so that ESI points to the rest of the string after some delimiter and the first part of the string before the delimiter is stored in a register.
  After Call strtok  with the delimiter of ' ' the result should be ESI = 'Two Three' and some other register = 'One'</p>
  
  <p>Using the code below i can find the index of the first instance of a space ' ' in string stored at EDI. index at the end is stored in EAX, the rest of the string after the delimiter is located is stored back in edi and then moved to esi. so 'One Two Three' ESI becomes 'Two Three'. My question would be how do I keep track of the first part of the string before the delimiter. So in this example how do i store 'One' in a register when it looks like repne scasb deletes the first part of the string up until the delimiter.</p>
  
  <pre><code>    strtok:
          Mov Ecx, 0  ;reset ecx to 0
          Not Ecx     ;set Ecx to -1 or highest possible integer
          Mov Al, ' ' ;Initialize a1 to delimiter of (space) ' '
          Cld         ;Clear Direction Pointer
          Repne Scasb ;scan edi one byte at a time until delimiter found
          Not Ecx
          Dec Ecx
          Lea Eax, [Ecx] ;Set Eax to index of found delimiter
  
          Xchg Esi, Edi  ;Take Edi which is now equal to string after found delimiter and put in esi
  </code></pre>