title: 8086 TASM Assembler - Error when looping: "Value out of range"?
body: <p>I always seem to fall behind the group in my class, and I wanted to "practice" for the next chapter in my class on Assembly, which is about loops.  </p>
  
  <p>I wrote this small loop to count from 1 to 10,000 (which I figured would take all of a millisecond to run):</p>
  
  <pre><code>    .MODEL SMALL
  
      .STACK 100h
  
      .DATA   
      Finished DB 10, 13, 'Loop x 10,000 finished.  Congratulations! $', 10, 13
  
      .CODE
  
      MAIN PROC
  
              MOV AX, @data            
              MOV DS, AX
  
              MOV CX, 10000            
              MOV BX, 0                
  
      StrtLoop:                        
  
              INC BX                   
  
      LOOP StrtLoop                    
  
              CMP BX, 10000                
              JE DispMsg               
  
  
              JMP SkipMsg              
  
      DispMsg:                         
              MOV AH, 09H             
              MOV DX, OFFSET Finished
              INT 21H
      SkipMsg:                         
              MOV AL, 0h               
              MOV AH, 4CH
              INT 21H
  
      MAIN ENDP
      END MAIN
  </code></pre>
  
  <p>I mistyped the number of zeroes a few minutes ago, and broke the program.  I was wondering why this happened.  </p>
  
  <p>I got this error:</p>
  
  <p>Assembling file:  Loop.ASM</p>
  
  <p><strong>ERROR</strong> loop.ASM(15) Value out of range.</p>
  
  <p><strong>ERROR</strong> loop.ASM(24) Value out of range.</p>
  
  <p>Error messages: 2</p>
  
  <p>Warning messages: None</p>
  
  <p>Passes: </p>
  
  <p>Remaining memory: 467k</p>
  
  <pre><code>    .MODEL SMALL
  
      .STACK 100h
  
      .DATA   
      Finished DB 10, 13, 'Loop x 100000 finished.  Congratulations! $', 10, 13
  
      .CODE
  
      MAIN PROC
  
              MOV AX, @data            
              MOV DS, AX
  
              MOV CX, 100000               
              MOV BX, 0                
  
      StrtLoop:                        
  
              INC BX                   
  
      LOOP StrtLoop                    
  
              CMP BX, 100000               
              JE DispMsg               
  
  
              JMP SkipMsg              
  
      DispMsg:                         
              MOV AH, 09H             
              MOV DX, OFFSET Finished
              INT 21H
      SkipMsg:                         
              MOV AL, 0h               
              MOV AH, 4CH
              INT 21H
  
      MAIN ENDP
      END MAIN
  </code></pre>
  
  <p>After some Google searches (and fumbling around the book reading about memory registers), it turns out that there is a hard limit of 65,535 bytes.  Is this correct?  What if someone wanted to go beyond this memory limit?  Is there a way to do it?</p>
  
  <p>It just seems strange to me...</p>