title: CONCEPT OF MOV AX,CS and MOV DS,AX
body: <p>Can someone please explain the functions of these three instructions?</p>
  
  <pre><code>  ORG 1000H 
    MOV AX,CS
    MOV DS,AX
  </code></pre>
  
  <p>I know what the code, data, and extra segments are in theory, but:</p>
  
  <ol>
  <li><p>How they are implemented in this program? </p></li>
  <li><p>Why is the entire segment moved into another? (<code>MOV AX,CS</code> and <code>MOV DS,AX</code>)</p></li>
  </ol>
  
  <p>What do these two instructions <em>actually do</em>?</p>
  
  <p>I can understand the meaning of every other instruction in this code, except for the highlighted 3 instructions.</p>
  
  <p>(The program works fine. It accepts input till 0 is hit -- there's a <code>mov ah,01h</code> and an <code>int 21h</code>, then it compares <code>al</code> to <code>'0'</code> and if <code>al</code> is <code>'0'</code>, it jumps to <code>last</code>, otherwise it jumps into <code>back</code>.)</p>
  
  <pre><code>    ASSUME CS:CODE        
      CODE SEGMENT 
      ORG 1000H
      MOV AX,CS
      MOV DS,AX
  BACK:
      MOV AH,01H
      INT 21H
      CMP AL,'0'
      JZ LAST
      JMP BACK
  LAST:
      MOV AX,4C00H
      INT 21H
      CODE ENDS
  
      END
  </code></pre>
  
  <p>(Editor's note: <code>.com</code> programs are loaded at offset <code>100h</code>, with all segment registers set equal to each other.  <code>org 1000h</code> is likely a typo for <code>org 100h</code> because this looks like a <code>.com</code> program.  This program doesn't break because it doesn't use any absolute addresses, only relative jumps.)</p>