Wednesday, 29 July 2015

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 In Assembly Language Solution.

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.

/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

TAG: EASY SOLUTION , 8086 MICROPROCESSOR, ASSEMBLY LANGUAGE CHAPTER 6 , PROGRAMMING EXERCISE ,
 ASSEMBLY LANGUAGE PROGRAMMING AND ORGANIZATION OF THE IBM PC - CHAPTER 6 .

Solution:

.MODEL SMALL
.STACK 100H
.DATA
    PROMPT_TRY_MSG DB 'TRY AGAIN.$'
    PRMPT_MSG_1 DB 'ENTER A HEX DIGIT "0"..."9"  OR "A".."F": $'
    OUTPUT_PRMPT DB 0AH,0DH,'OUTPUT: $'
    ASK_PROMPT DB 0AH,0DH,'DO YOU WANT ANOTHER INPUT: $'
.CODE
MAIN PROC
 
    MOV AX,@DATA
    MOV DS,AX
 
    TOP:
        MOV AH,9
        LEA DX,PRMPT_MSG_1
        INT 21H
     
        MOV AH,1
        INT 21H
        MOV BL,AL
     
        CMP BL,30H
        JL  TRY_MSG
     
        CMP BL,46H
        JG  TRY_MSG
     
        CMP BL,39H
        JLE DIGIT
     
        MOV AH,9
        LEA DX,OUTPUT_PRMPT
        INT 21H
     
        SUB BL,11H
     
        MOV AH,2
        MOV DL,31H
        INT 21H
        MOV DL,BL
        INT 21H      
    AGAIN:
        MOV AH,9
        LEA DX,ASK_PROMPT
        INT 21H
     
        MOV AH,1
        INT 21H
        MOV BH,AL
        MOV AH,2
        MOV DL,0AH
        INT 21H
        MOV DL,0DH
        INT 21H
         
        CMP BH,'Y'
        JE TOP
        CMP BH,'y'
        JE TOP
        JMP END_
    DIGIT:
        MOV AH,9
        LEA DX,OUTPUT_PRMPT
        INT 21H
     
        MOV AH,2
        MOV DL,BL
        INT 21H
     
        JMP AGAIN
    TRY_MSG:
        MOV AH,9
        LEA DX,PROMPT_TRY_MSG
        INT 21H
        JMP TOP      
    END_:
 
    MOV AH,4CH
    INT 21H
     
    MAIN ENDP
END MAIN

No comments:

Post a Comment