title: Assembly string instructions register DS and ES in real mode
body: <p>I have been studying this assembly program from my book and I have a question about it. The purpose of this program is to simply copy string1 to string2. My question relates to the following two instructions:</p>
  
  <pre><code>mov    AX,DS        
  mov    ES,AX 
  </code></pre>
  
  <p>I see without them, the program doesn't work properly, but I would have thought by pointing <code>ESI</code> to string1 and <code>EDI</code> to string2, that would be all you need to do. Then just increment <code>ESI</code> and <code>EDI</code> and move it character by character. What exactly does <code>DS</code> hold and why do we need to move it to <code>ES</code>?</p>
  
  <pre><code>.DATA
  string1    db    'The original string',0
  strLen     EQU   $ - string1
  .UDATA
  string2    resb    80
  .CODE
      .STARTUP
      mov    AX,DS          ; set up ES
      mov    ES,AX          ;  to the data segment
      mov    ECX,strLen     ; strLen includes NULL
      mov    ESI,string1
      mov    EDI,string2
      cld                   ; forward direction
      rep    movsb
  </code></pre>