Convert Binary Number to ASCII Code in 8085 Microprocessor

In this tutorial, we will learn how to convert binary number to ASCII code in 8085 Microprocessor? By Ayush Sharma Last updated : May 13, 2023

8085 code to convert binary number to ASCII code

Problem Statement

Write an assembly level program in 8085 which converts a binary number into ASCII number.

Assumptions

Binary number which has to convert in ASCII value is stored at memory location 2050 and output will be displayed at memory location 3050 and 3051.

Algorithm

  1. Load the content of 2050.
  2. Then separate the LSB of the no. using ANI 0F instruction and MSB of the number by again loading the content of 2050 and rotate it by one bit 4 times to get reverse of the number and then again use ANI 0F to separate the digit.
  3. If the digit is more than or equal to 0A (in hexadecimal) then add 37 otherwise add 30 to convert into ASCII value (For checking the number is greater than or equal to A then use instruction: CPI 0A and then check the carry flag, if it is 0 then it means digit is greater than or equal to A and if 1 digit is less than A).
  4. Now Store the ASCII values of both the digits in 3050 and 3051 respectively.

Main Routine

ADDRESSMNEMONICSCOMMENTS
2000LDA 2050A<-[2050]
2003CALL 2500go to address 2500
2006STA 3050A->[3050]
2009LDA 2050A<-[2050]
200CRLCRotate the number by one bit to left without carry
200DRLCRotate the number by one bit to left without carry
200ERLCRotate the number by one bit to left without carry
200FRLCRotate the number by one bit to left without carry
2010CALL 2500go to address 2500
2013STA 3051A->[3051]
2016HLTTerminates the program

Explanation of Main Routine

  1. LDA 2050: This instruction will load the number from address 2050 to the accumulator.
  2. CALL 2500: This instruction will stop executing the main routine instructions after it and will move to the subroutine address 2500 for performing the subtask and after performing subroutine instructions it will come back to mainroutine and execute the instructions after CALL 2500.
  3. STA 3050: This instruction will store the result (performed in subroutine) of Accumulator to address 3050.
  4. LDA 2050: This instruction will again load the number from address 2050 to the accumulator as the earlier loaded number is changed in accumulator.
  5. RLC: Rotate the contents of Accumulator by one bit left side without carry.
  6. RLC: Rotate the contents of Accumulator by one bit left side without carry.
  7. RLC: Rotate the contents of Accumulator by one bit left side without carry.
  8. RLC: Rotate the contents of Accumulator by one bit left side without carry.
  9. (Applying RLC 4 times it will reverse the contents of the Accumulator)
  10. CALL 2500: This instruction will stop executing the main routine instructions after it and will move to the subroutine address 2500 for performing the subtask and after performing subroutine instructions it will come back to mainroutine and execute the instructions after CALL 2500.
  11. STA 3051: This instruction will store the result (performed in subroutine) of Accumulator to address 3051.
  12. HLT: This instruction will terminate the program.

Sub Routine

ADDRESSMNEMONICSCOMMENTS
2500ANI 0FA<-[A] AND 0F
2502CPI 0A[A]-0A
2504JNC 250A Jump to [250A] if carryflag is 0
2507ADI 30A<-[A]+30
2509RETReturn to the next instruction from where subroutine address was called in main routine
250AADI 37A<-[A]+37
250CRETReturn to the next instruction from where subroutine address was called in main routine

Explanation of Sub Routine

  1. ANI 0F: This instruction will separate the LSB of the number present in Accumulator and stores the result back in Accumulator.
  2. CPI 0A: This instruction will compare the content of Accumulator with 0A i.e. [A]-0A.
  3. JNC 205A: If the carryflag becomes 0 then it will jump to 205A otherwise move to the next instruction.
  4. ADI 30: It will add 30 to the content of Accumulator and again store the result back in Accumulator.
  5. RET: Now it will move back to the main routine after the next instruction of CALL and start executing instructions of main routine.
  6. <="" strong=""> It will add 37 to the content of Accumulator and again store the result back in Accumulator.
  7. RET: Now it will move back to the main routine after the next instruction of CALL and start executing instructions of main routine.




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.