title: Coverting String Decimal to Binary and Hexa in Assembly 8086
body: <p>I'm trying to convert a string I read with this code to binary and hexa.</p>
  
  <pre><code>READ_STRING:
      MOV DX, offset buffer
      MOV AH, 0Ah
      INT 21h
      MOV SI, 1d
      MOV AX, 0
      XOR CX, CX
      MOV CL, buffer[SI]
      INC SI
  
  LOOP_1:
      MOV DX, 10
      MUL DX
      MOV DL, buffer[SI]
      SUB DL, 30h
      MOV DH, 0
      ADD AX, DX
      INC SI
      LOOP LOOP_1
  
      RET
  </code></pre>
  
  <p>So far I have this code for binary output but it always prints "1001" (9 in decimal):</p>
  
  <pre><code>NEXT:
  
      XOR AX, AX
      XOR BX, BX
      XOR CX, CX
      MOV CL, 2
      MOV AL, byte ptr[nombre]
      MOV DI, offset binaire
  
  ; DIV : divide AX by CL. Remainder in AH and result in AL
  
  LOOP:
      DIV CL ; remainder in AH, quotient in AL
      ADD AH, '0' ;  0 -&gt; '0' , 1 -&gt; '1'
      MOV [DI], AH ; Saves the remainder in the array
      INC DI
      MOV AH, 0 ; reset AH for next division
      CMP AL, 0 ; if result is 0, end
      JNE LOOP
  
  ;Prints the binary number               
      MOV DX, offset binaire
      CALL WRITE_STRING
  </code></pre>
  
  <p>Thanks! If you need anything else just ask.</p>