Open In App
Related Articles

8085 program to convert an 8 bit BCD number into hexadecimal number

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Problem – Write an assembly language program in 8085 microprocessor to convert an 8 bit BCD number into hexadecimal number. Assumptions – Assume that starting address of the program is 2000, input memory locations, 2050, 2051, and output memory location is 2052. Example –

INPUT: 2050:02H
       2051: 09H

OUTPUT:2052: 1DH 

Algorithm –

  1. Initialize memory pointer to 2050
  2. Get the most significant digit
  3. Multiply the MSD by 10 using repeated addition
  4. Add LSD to result obtained in above step
  5. Store the converted result in memory 2052

Program –

Memory AddressMnemonicsComments
2000LXI H, 2050 
2003MOV A, MA<-M
2004ADD AA<-A+A
2005MOV B, AB<-A
2006ADD AA<-A+A
2007ADD AA
2008ADD BA<-A+B
2009INX H 
200AADD MA<-A+M
200BINX H 
200CMOV M, AM<-A
200DHLTTERMINATE THE PROGRAM

Explanation – Registers H, L, B, A are used for general purpose.

  1. LXI H, 2050: will load the HL pair register with the address 2050 of memory location.
  2. MOV A, M: copies the content of memory into register A.
  3. ADD A: add the content of accumulator with itself.
  4. MOV B, A: move the content of accumulator into register B.
  5. ADD A: add the content of accumulator with itself.
  6. ADD A: add the content of accumulator with itself.
  7. ADD B: add the content of accumulator with register B and store the result in accumulator.
  8. INX H: increment register pair HL.
  9. ADD M: add the content of accumulator with memory and store the result in accumulator.
  10. INX H: increment register pair HL.
  11. MOV M, A: copies the content of accumulator into memory.
  12. HLT: stops executing the program and halts any further execution.


Advantages:

  • This program is efficient and easy to understand, making it accessible for programmers with varying levels of experience.
     
  • The program handles a common conversion operation that may be useful in various applications.
     
  • The program can be easily modified to handle different input sizes or output formats.
     
  • The program outputs the result in ASCII format, which is easy to display or manipulate in software.
     

Disadvantages:

  • The program assumes that the input is an 8-bit BCD number and does not handle other input formats.
     
  • The program outputs the result in ASCII format, which may not be suitable for all use cases.
     
  • The program assumes that the output location is fixed and does not allow for dynamic memory allocation.
     
  • The program does not check for errors or handle exceptional cases, such as invalid input or overflow situations.

Last Updated : 11 Apr, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads