8085 Program to convert HEX to ASCII



Now let us see a program of Intel 8085 Microprocessor. This program will convert HEX to ASCII values.

Problem Statement

Write 8085 Assembly language programs to convert Hexadecimal characters to ASCII values.

Discussion

We know that the ASCII of number 00H is 30H (48D), and ASCII of 09H is39H (57D). So all other numbers are in the range 30H to 39H. The ASCII value of 0AH is 41H (65D) and ASCII of 0FH is 46H (70D), so all other alphabets (B, C, D, E, F) are in the range 41H to 46H.

Here we are providing hexadecimal digit at memory location 8000H, The ASCII equivalent is storing at location 8001H.

The logic behind HEX to ASCII conversion is very simple. We are just checking whether the number is in range 0 – 9 or not. When the number is in that range, then the hexadecimal digit is numeric, and we are just simply adding 30H with it to get the ASCII value. When the number is not in range 0 – 9, then the number is range A – F, so for that case, we are converting the number to 41H onwards.

In the program at first, we are clearing the carry flag. Then subtracting 0AH from the given number. If the value is numeric, then after subtraction the result will be negative, so the carry flag will be set. Now by checking the carry status, we can just add 30H with the value to get ASCII value.

In other hands when the result of the subtraction is positive or 0, then we are adding 41H with the result of the subtraction.

Input

first input

Address Data
.
.
.
.
.
.

8000 0A
.
.
.

.
.
.

second input

Address Data
.
.
.

.
.
.

8000 05
.
.
.

.
.
.

third input

Address Data
.
.
.

.
.
.

8000 0F
.
.
.

.
.
.

Flow Diagram

Program

Address HEX Codes Labels Mnemonics Comments
F000 21,00, 80

LXIH, 8000H Load address of the number
F003 7E

MOVA, M Load Acc with the data from memory
F004 47

MOVB,A Copy the number into B
F005 37

STC
Set Carry Flag
F006 3F

CMC Complement Carry Flag
F007 D6,0A

SUI0 AH Subtract 0AH from A
F009 DA,11, F0

JCNUM When the carrier is present, A is numeric
F00C C6,41

ADI 41H Add 41H for Alphabet
F00E C3,14, F0

JMP STORE Jumpto store the value
F011 78 NUM MOVA, B Get back B to A
F012 C6

ADI 30H Add 30H with A to get ASCII
F014 23 STORE INX H Point to next location to store address
F015 77

MOVM,A Store A to the memory location pointed by HL pair
F016 76

HLT Terminate the program

Output

first output

Address Data
.
.
.

.
.
.

8001 41
.
.
.

.
.
.

second output

Address Data
.
.
.

.
.
.

8001 35
.
.
.

.
.
.

third output

Address Data
.
.
.
.
.
.
8001 46
.
.
.
.
.
.
Updated on: 2020-06-26T10:53:12+05:30

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements