6. To convert given Hexadecimal number into its equivalent ASCII number and vice versa using 8085 instruction set.

 ORG 0000h    ; Starting address of the program


; Convert hexadecimal number to ASCII

LXI H, 1234h  ; Load the hexadecimal number in HL

MOV C, 2      ; Set the counter to 2 (since there are 2 bytes in the hexadecimal number)

HEXTOASCII:

MOV A, H      ; Load the high byte of the hexadecimal number in A

ANI 0Fh      ; Mask the lower 4 bits (since each digit in hexadecimal is represented by 4 bits)

ADD 30h      ; Add 30h to convert the digit to its ASCII equivalent

STA 4000h    ; Store the ASCII digit in memory location 4000h

INX H         ; Move to the next byte of the hexadecimal number

DCR C         ; Decrement the counter

JNZ HEXTOASCII ; Jump back to HEXTOASCII if counter is not zero


; Convert ASCII number to hexadecimal

LXI H, 4000h  ; Load the ASCII number in HL

MOV C, 2      ; Set the counter to 2 (since there are 2 digits in the ASCII number)

ASCIITOHEX:

MOV A, M      ; Load the current ASCII digit in A

CPI 30h      ; Compare the ASCII digit with 30h (the ASCII code for '0')

JC SKIP      ; Jump to SKIP if the ASCII digit is less than 0 (i.e., not a digit)

SUB 30h      ; Subtract 30h to convert the ASCII digit to its hexadecimal equivalent

ORA A        ; Set the accumulator flags

JMP STORE    ; Jump to STORE

SKIP:

CPI 41h      ; Compare the ASCII digit with 41h (the ASCII code for 'A')

JC SKIP2     ; Jump to SKIP2 if the ASCII digit is less than 41h (i.e., not a letter)

SUB 37h      ; Subtract 37h to convert the ASCII letter to its hexadecimal equivalent

ORA A        ; Set the accumulator flags

JMP STORE    ; Jump to STORE

SKIP2:

MOV A, 0     ; If neither a digit nor a letter, set A to 0

STORE:

STA 5000h    ; Store the hexadecimal digit in memory location 5000h

INX H         ; Move to the next ASCII digit

DCR C         ; Decrement the counter

JNZ ASCIITOHEX ; Jump back to ASCIITOHEX if counter is not zero