title: Assembly Conversion hexadecimal to decimal (4 digit max)
body: <p>This code converts 1 digit hexadecimal to decimal, it's working, copy the internet, but I want to understand a little better how it works, and add a loop where I can get up to 4 digits.I would like a help on how to perform this loop.</p>
  
  <p>I'm using masm16 and DosBox.</p>
  
  <pre><code>    .model small
  .stack 100h
  .data
  msg1 db 10,13,'ENTER A HEX DIGIT:$'
  msg2 db 10,13,'IN DECIMAL IS IT:$'
  msg3 db 10,13,'DO YOU WANT TO DO IT AGAIN?$'
  msg4 db 10,13,'ILLEGAL CHARACTER- ENTER 0-9 OR A-F:$'
  
  .code
  
  again:
  
     mov ax,@data
     mov ds,ax
     lea dx,msg1
     mov ah,9
     int 21h
  
     mov ah,1
     int 21h
  
     mov bl,al
  
     jmp go
  
  go:
  
     cmp bl,'9'
     ja hex
     jb num
     je num
  
   hex:
  
      cmp bl,'F'
      ja illegal
  
     lea dx,msg2
     mov ah,9
     int 21h
  
      mov dl,49d
      mov ah,2
      int 21h
  
      sub bl,17d
      mov dl,bl
      mov ah,2
      int 21h
  
      jmp inp
  
   inp:
  
      lea dx,msg3
      mov ah,9
      int 21h
  
      mov ah,1
      int 21h
  
      mov cl,al
      cmp cl,'y'
      je again
      cmp cl,'Y'
      je again
      jmp exit
  
   num:
  
     cmp bl,'0'
     jb illegal
  
     lea dx,msg2
     mov ah,9
     int 21h
  
     mov dl,bl
     mov ah,2
     int 21h
  
     jmp inp
  
   illegal:
  
         lea dx,msg4
         mov ah,9
         int 21h
  
         mov ah,1
         int 21h
  
         mov bl,al
  
         jmp go
  
  exit:
  end
  </code></pre>