; Write a program to read one of the hex digits A-F, and display it on the next line in decimal.
.MODEL SMALL
.STACK 100H
.DATA
MSG_1 DB 'Enter the Hex digit (A-F) : $'
MSG_2 DB 0DH,0AH,'The corresponding Decimal dgit is : $'
HEX DB ?
.CODE
MAIN PROC
MOV AX, @DATA ; initialize DS
MOV DS, AX
MOV AH, 9
LEA DX, MSG_1 ; load and display MSG_1
INT 21H
MOV AH, 1
INT 21H
MOV HEX, AL ; read the hex digit
SUB HEX, 11H ; convert the character into second digit by subtracting 11H
MOV AH, 9
LEA DX, MSG_2 ; load and display MSG_2
INT 21H
MOV AH, 2
MOV DL, 31H ; display the first decimal digit i.e. 1
INT 21H
MOV DL, HEX
INT 21H
MOV AH, 4CH ; return control to DOS
INT 21H
MAIN ENDP
END MAIN
.MODEL SMALL
.STACK 100H
.DATA
MSG_1 DB 'Enter the Hex digit (A-F) : $'
MSG_2 DB 0DH,0AH,'The corresponding Decimal dgit is : $'
HEX DB ?
.CODE
MAIN PROC
MOV AX, @DATA ; initialize DS
MOV DS, AX
MOV AH, 9
LEA DX, MSG_1 ; load and display MSG_1
INT 21H
MOV AH, 1
INT 21H
MOV HEX, AL ; read the hex digit
SUB HEX, 11H ; convert the character into second digit by subtracting 11H
MOV AH, 9
LEA DX, MSG_2 ; load and display MSG_2
INT 21H
MOV AH, 2
MOV DL, 31H ; display the first decimal digit i.e. 1
INT 21H
MOV DL, HEX
INT 21H
MOV AH, 4CH ; return control to DOS
INT 21H
MAIN ENDP
END MAIN
No comments:
Post a Comment