Open In App

8085 code to convert binary number to ASCII code

Last Updated : 08 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Problem – Assembly level program in 8085 which converts a binary number into ASCII number. Example – Assumptions – Binary number which have 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.

Program – Main routine:

ADDRESS MNEMONICS COMMENTS
2000 LDA 2050 A<-[2050]
2003 CALL 2500 go to address 2500
2006 STA 3050 A->[3050]
2009 LDA 2050 A<-[2050]
200C RLC Rotate the number by one bit to left without carry
200D RLC Rotate the number by one bit to left without carry
200E RLC Rotate the number by one bit to left without carry
200F RLC Rotate the number by one bit to left without carry
2010 CALL 2500 go to address 2500
2013 STA 3051 A->[3051]
2016 HLT Terminates the program

Sub routine:

ADDRESS MNEMONICS COMMENTS
2500 ANI 0F A<-[A] AND 0F
2502 CPI 0A [A]-0A
2504 JNC 250A Jump to [250A] if carryflag is 0
2507 ADI 30 A<-[A]+30
2509 RET Return to the next instruction from where subroutine address was called in main routine
250A ADI 37 A<-[A]+37
250C RET Return to the next instruction from where subroutine address was called in main routine

Explanation – 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. (Applying RLC 4 times it will reverse the contents of the Accumulator) 
     
  9. 9. 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.
  10. 10. STA 3051: This instruction will store the result (performed in subroutine) of Accumulator to address 3051.
  11. 11. HLT: This instruction will terminate the program.

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. 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.

Advantages of converting binary number to ASCII code:

  1. Converting a binary number to ASCII code is a common operation used in many applications, such as displaying binary data on a computer screen or printing binary data to a printer.
     
  2. It is a simple and straightforward task that can be easily implemented in any programming language.
     
  3. It is a fast operation that can be completed in O(n) time complexity, where n is the number of bits in the binary number.
     

Disadvantages of converting binary number to ASCII code:

  1. If the binary number is very large, storing the entire number in memory may not be feasible, which could require a more complex solution such as processing the binary number in smaller parts.
     
  2. If the binary number is negative, additional logic is required to handle the sign bit and convert it to a negative ASCII code.
     
  3. If the ASCII code is being displayed on a computer screen or printed to a printer, the font used to display the characters may not be able to display all ASCII codes correctly, which could result in distorted or unreadable characters.

Next article: 8085 program to convert 8 bit BCD number into ASCII Code


Previous Article
Next Article

Similar Reads

8085 program to convert ASCII code into HEX code
Problem - Write an assembly level language program to convert ASCII code to its respective HEX Code. Examples: Input: DATA: 31H in memory location 2050Output:DATA: 0BH in memory location 3050 Assume that starting address of program, input memory location, and output memory locations are 2000, 2050, and 3050 respectively. Algorithm - Input the conte
1 min read
8085 program to convert a hexadecimal number into ASCII code
Problem: Write an assembly-level language program to convert the HEX code to its respective ASCII code. Assume that the starting address of the 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: Load the given data in accumulator
2 min read
8085 program to convert 8 bit BCD number into ASCII Code
Problem – Write an assembly-level language program to convert 8-bit BCD number to its respective ASCII Code. Assumptions - Starting address of program: 2000 Input memory location: 2050 Output memory location: 3050 and 3051 ASCII Code for Digits 0 – 9  Example -  Algorithm -   Input the content of 2050 in accumulator  Move content of Accumulator to
3 min read
What is ASCII - A Complete Guide to Generating ASCII Code
The American Standard Code for Information Interchange, or ASCII, is a character encoding standard that has been a foundational element in computing for decades. It plays a crucial role in representing text and control characters in digital form. Historical BackgroundASCII has a rich history, dating back to its development in the early 1960s. Origi
13 min read
8085 program to convert a BCD number to binary
Problem – Write an assembly language program for converting a 2 digit BCD number to its binary equivalent using 8085 microprocessor. Examples: Input : 72H (0111 0010)2Output : 48H (in hexadecimal) (0011 0000)2((4x16)+(8x1))=72Algorithm: Load the BCD number in the accumulatorUnpack the 2 digit BCD number into two separate digits. Let the left digit
2 min read
Substring with maximum ASCII sum when some ASCII values are redefined
Given a string W, and two arrays X[] and B[] of size N each where the ASCII value of character X[i] is redefined to B[i]. Find the substring with the maximum sum of the ASCII (American Standard Code for Information Interchange) value of the characters. Note: Uppercase &amp; lowercase both will be present in the string W. Input: W = "abcde", N = 1,
9 min read
Check if a string contains a non-ASCII value in Julia - ascii() Method
The ascii() is an inbuilt function in Julia which is used to convert a specified string to a String type and also check the presence of ASCII data. If the non-ASCII byte is present, throw an ArgumentError indicating the position of the first non-ASCII byte. Syntax: ascii(s::AbstractString) Parameters:s::AbstractString: Specified stringReturns: It r
1 min read
ASCII NULL, ASCII 0 ('0') and Numeric literal 0
The ASCII (American Standard Code for Information Interchange) NULL and zero are represented as 0x00 and 0x30 respectively. An ASCII NULL character serves as a sentinel character of strings in C/C++. When the programmer uses '0' in his code, it will be represented as 0x30 in hex form. What will be filled in the binary integer representation in the
3 min read
8086 program to convert 8 bit BCD number into ASCII Code
Problem – Write an assembly language program in 8086 microprocessor to convert 8-bit BCD number to its respective ASCII Code. Assumption – Starting address of the program: 400 Input memory location: 2000 Output memory location: 3000 Example : Input: DATA: 98H in memory location 2000Output:DATA: 38H in memory location 3000 and 39H in memory location
2 min read
8085 program to convert an 8 bit number into Grey number
Prerequisite - Binary to/from Gray Code Problem - Write an assembly language program in 8085 which convert an 8 bit number into grey number Example - Assumption - 8 bit number (input) is stored at memory location 2050 and output to be stored at memory location 3050. Algorithm - Load the content of memory location 2050 in AccumulatorReset carry flag
2 min read