[Assembly 8086] Convert Hexadecimal To Decimal











Write a program that will prompt the user to enter a hex digit
character ("0"· ... "9" or "A" ... "F"), display it on the next line
in decimal, and ask the user i.i he or she wants to do it again. If
the user types "y" or "Y", the ·program repeats; If the user types
anything else, the program terminates. If the user enters an illegal
character, prompt the user to try again.



ENTER A HEX DIGIT: 9
IN DECIMAL IS IT 9
DO YOU WANT TO DO IT AGAIN? y
ENTER A HEX DIGIT: c
ILLEGAL CHARACTER - ENTER 0 .. 9 OR A .. F: C
IN DECIMAL IT IS 12
DO YOU WANT TO DO IT AGAIN? N





.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:
Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment