8085 program to convert a hexadecimal number into ASCII code

Problem: Write an assembly level language program to convert HEX code to its respective ASCII code.
Assume that starting address of program and input memory location are 2000 and 2050 respectively.

Example:

Input: 2050 E4 (Hex data)

Output:
2051 34 (ASCII code for 4)
2052 45 (ASCII code for E) 

Algorithm:



  1. Load the given data in accumulator and move to B register
  2. Mask the most significant 4 bits(upper nibble) of the Hexa decimal number in accumulator.
  3. Call subroutine to get ASCII of least significant 4 bits.
  4. Store it in memory
  5. Move B register to accumulator and mask the least significant 4 bits(lower nibble).
  6. Rotate the upper and lower nibble position.
  7. Call subroutine to get ASCII of upper nibble
  8. Store it in memory
  9. Terminate the program.

Code:

MEMORY ADDRESS MNEMONICS COMMENTS
2000 LDA 2050H Load the hex data
2003 MOV B, A move content of accumulator to B
2004 ANI OFH mask upper nibble
2006 CALL SUB1 get ascii code for upper nibble
2009 STA 2051H
2012 MOV A, B move content of B to accumulator
2013 ANI F0H mask lower nibble
2015 RLC
2016 RLC
2017 RLC
2018 RLC
2019 CALL SUB1 get ascii code for lower nibble
2022 STA 2052H
2025 HLT
SUB1 CPI 0AH
JC SKIP
ADI 07H
SKIP ADI 30H
RET

Explanation:

  1. LDA 2050H: load the content of memory location 2050H in accumulator.
  2. MOV B, A: copies the content of accumulator to register B.
  3. ANI OFH: AND operation is performed between accumulator and 0FH value.
  4. CALL SUB1: the subroutine at memory location SUB1 is called.
  5. STA 2051H: store the content of accumulator in the memory location 2051H.
  6. MOV A, B: copies the content of register B to accumulator.
  7. ANI F0H: AND operation is performed between accumulator and F0H value.
  8. RLC: rotate accumulator left.
  9. HLT: stops executing the program and halts any further execution.
  10. CPI 0AH: compare accumulator content with 0AH value.
  11. JC SKIP: jump to memory location SKIP if the carry bit is set.
  12. ADI 07H: add 07H value to the content of accumulator.
  13. RET: Return from the subroutine unconditionally.


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.