title: Converting number to ascii in 8086
body: <p>in 8086(tasm) I trying to print out number to the screen. The below code works for most number but fails for 15876. <strong>My question is how would repeatedly divide 16876 and get its digits as reminder? or is there a better to print 15876?</strong></p>
  
  <p>Thank You.</p>
  
  <pre><code>    lea si,answerst         ;holds output
      add si,5                ;max length of ans
  
      ;add a $ at the end
      mov bh,24h      
      mov [si],bh
      dec si        ;decrements si 
  
      mov bx,15876  ;the number to print
      mov ax,bx     ;put it in ax because div uses ax
      mov cx,10     ;10 is the dividend
  
  spctostring:
      cmp al,0      ;if the quotient is zero you have reached the end of the num          
      je stringme   ;if you have reached the end of the num print it out
  
      div cl        ;divide by 10     
      mov bh,ah     ;put the reminder in bh
      mov ah,0      ;resets ah
  
      add bh,30h    ;add 30 hex to get ascii value
      mov [si],bh   ;place the char in the output string
      dec si        ;decrements si
  
      jmp spctostring
  
  stringme:
  ;---------------Output-------------------
      mov ah,09h      ;print string cmd 
      lea dx,numone   ;string to print
      int 21h         ;print interrupt
  </code></pre>