title: Copying a string in x86 assembly using indirect addressing
body: <p>I am still very new to assembly and only tonight have started to even begin to understand the majority of what I'd like to do so I may have many things wrong but it is hard for me to tell where due to lack of experience.</p>
  
  <p>I am attempting to copy a string from source to target using indirect addressing in x86 assembly. I am trying to apply the understanding I have from this explanation but am struggling to understand how exactly to copy the data @ esi into edi. </p>
  
  <pre><code>.data
  val1 BYTE 10h,20h,30h
  .code
  mov esi,OFFSET val1
  mov al,[esi]    ; dereference ESI (AL = 10h)
  
  inc esi
  mov al,[esi]    ; AL = 20h
  
  inc esi
  mov al,[esi]    ; AL = 30h
  </code></pre>
  
  <p>This is what I've done so far and I've actually gotten it to run (!!!) but unfortunately it does not copy at all. I suspect that my loop is bad (I'm not sure exactly how to exit it properly) and there is something crazy going on with my copying but I do not know where I am going wrong:</p>
  
  <pre><code>INCLUDE Irvine32.inc
  .data
     source  BYTE  "Source string I want to copy",0
     target  BYTE  SIZEOF source DUP(0)
  
  .code
  main PROC
      mov  esi,OFFSET source              
      mov  edi,OFFSET target             
  L1:
      mov  al,[esi]       ; get char from source
      mov  [edi],al       ; store it in target
      inc  esi            ;move to next char in source
      inc  edi            ;move to next position in target
      cmp al, 28          ;compare al to 28 (the number of chars in source string)
      JNZ L1              ;repeat the loop if al != 28 (length of source string)
  
      mov edx, OFFSET source 
      call WriteString ;Prints out source string (working fine)
      mov edx, OFFSET target
      call WriteString ;Prints out dest string (working fine)
  </code></pre>
  
  <p>The writestrings are working properly at the bottom because I was able to get it to output "Source string I want to copySource string I want to copy" into the console when running using indexed addressing. </p>