Wednesday, 29 July 2015

Do programming exercise 10, except that if the user fails to enter a hex-digit character In three tries, display a message and terminate the program In Assembly Language Solution.

Do programming exercise 10, except that if the user fails to enter
a hex-digit character In three tries, display a message and terminate the program.

/*
    *
    * 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 0AH,0DH,'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
    MOV CL,0
    TOP:
        CMP CL,3
        JE END_
     
        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
        MOV CL,0
         
        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
        MOV CL,0
        JMP AGAIN
    TRY_MSG:
        MOV AH,9
        LEA DX,PROMPT_TRY_MSG
        INT 21H
        INC CL
        MOV AH,2
        MOV DL,0AH
        INT 21H
        MOV DL,0DH
        INT 21H
     
        JMP TOP      
    END_:
 
    MOV AH,4CH
    INT 21H
     
    MAIN ENDP
END MAIN

No comments:

Post a Comment