0

I need help converting ascii to hex. This is my code so far.

ASCII DB 0DH,0AH,'THE ASCII CODE OF $'
HEX DB ?,' IN HEX IS $'
CHAR DB ?,'$'
.CODE
MAIN PROC
;initialize DS
        MOV AX,@DATA
        MOV DS,AX
REPEAT:
        LEA DX,MSG              ;get message
        MOV AH,9                ;display string function
        INT 21H                 ;display it
        MOV AH,1                ;read char function
        INT 21H                 ;char in AL
    CMP AL,0DH      ;CR?
    JE  EXIT        ;yes, exit
        MOV BL,AL               ;move char from AL to BL
        MOV HEX,AL              ;move char from AL to HEX
        LEA DX,ASCII            ;get message
        MOV AH,9                ;display string function
        INT 21H                 ;display it
        LEA DX,HEX              ;get message
        MOV AH,9                ;display string function
        INT 21H                 ;display it
        MOV BH,2                ;there are 2 characters in our output
WHILE_:                          ;WHILE loop
        MOV CHAR,BL             ;move char from BL to CHAR
        MOV CL,4                ;number of bits to shift
        SHR CHAR,CL             ;shift right
        CMP CHAR,0AH            
        ADD CHAR,30h            ;convert char in '0'...'9'
        JMP END_IF              ;done converting
ELSE_:
        ADD CHAR,37h            ;convert char in 'A'...'F'
END_IF:
        MOV AH,2                ;display char function
        MOV DL,CHAR             ;the char is stored in CHAR
        INT 21H                 ;display it
        MOV CL,4                ;number of bits to rotate
        SHR CHAR,CL
        DEC BH                  ;next character
        CMP BH,0                ;more character?
        JG WHILE_                ;yes, go back
    JMP  REPEAT     ;go back to top
EXIT:        
;DOS exit
        MOV AH,4CH     
        INT 21H
MAIN ENDP

END MAIN

Any help would be appreciated

2
Contributors
1
Reply
10
Views
4 Years
Discussion Span
Last Post by Assembly Guy
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.