# Convert a binary number into ASCII number | 8085 Microprocessor

**Assembly level program in 8085 which converts a binary number into ASCII number**: Learn how to convert a binary number to ASCII number?

Submitted by Ayush Sharma, on October 29, 2018

**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:**

- Load the content of 2050.
- 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.
- 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).
- Now Store the ASCII values of both the digits in 3050 and 3051 respectively.

**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 of Main routine:**

- LDA 2050: This instruction will load the number from address 2050 to the accumulator.
- 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.
- STA 3050: This instruction will store the result (performed in subroutine) of Accumulator to address 3050.
- LDA 2050: This instruction will again load the number from address 2050 to the accumulator as the earlier loaded number is changed in accumulator.
- RLC: Rotate the contents of Accumulator by one bit left side without carry.
- RLC: Rotate the contents of Accumulator by one bit left side without carry.
- RLC: Rotate the contents of Accumulator by one bit left side without carry.
- 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)
- 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.
- STA 3051: This instruction will store the result (performed in subroutine) of Accumulator to address 3051.
- HLT: This instruction will terminate the program.

**Explanation of Sub routine:**

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

Related Tutorials

- Pin Description of 8051 Microcontroller
- Oscillator Frequency in Microcontrollers
- 8051 Microcontroller programming using Keil Uvision IDE
- How to upload HEX code to microcontrollers?
- Hello world program for 8051 Microcontroller
- Accessing Ports and Pins in 8051 Microcontroller
- Reading and Writing values in Microcontroller Ports
- Introduction to Microprocessor architecture and its description
- Addition of two 8 bits numbers in 8085 Microprocessor
- Addition of two 8-bits numbers in 8085 Microprocessor with carry
- Subtraction of Two 8 bits number with consideration of Borrow in 8085 Microprocessor
- Subtraction of Two 8 bits number without borrow in 8085 Microprocessor
- Division of two 8 bits numbers using 8085 Microprocessor
- Maximum of two 8 bits number in 8085 Microprocessor
- Minimum of Two 8 bits number in 8085 Microprocessor
- Multiplication of two 8 bits numbers using 8085 microprocessor with carry
- Reverse an 8 bits number | 8085 Microprocessor
- 1's and 2's Compliment of 8 bits number in 8085 Microprocessor
- Check for EVEN or ODD (8 bits) using 8085 Microprocessor

- Convert an 8 bits number into its Gray number | 8086 Microprocessor
- Access Flag register and exchange the content of flag register F with register B | 8085 Microprocessor
- Print the table of a given number | 8085 Microprocessor
- Addition of two 16 bits numbers in 8085 Microprocessor using 16 bits operation
- Swap two 16 bits numbers using direct addressing mode
- 2's Compliment of 8 bits number with carry
- Multiplication of two 8 bits numbers using logical instructions
- Addition of three 16 bits numbers | 8085 Microprocessor
- Fibonacci series program | 8085 Microprocessor
- Assembly language program in 8085 microprocessor to multiply two 16 bit numbers
- Write the 8085 instructions which reset the accumulator
- Addition of two 8-bit BCD numbers | 8085 Microprocessor
- Swap two 8-bit numbers using Direct addressing mode | 8085 Microprocessor
- Masking of lower and higher nibble of 8-bit number | 8085 Microprocessor
- Exchange content of HL register pair with DE register pair
- Flag registers of 8085 Microprocessor
- Find square of an 8-bit number | 8085 Microprocessor
- Find square root of an 8-bit number |8085 Microprocessor

What's New

- C Language MCQs
- Python MCQs
- Perl MCQs
- MongoDB MCQs
- Java MCQs
- C# MCQs
- Scala MCQs
- Blockchain MCQs
- AutoCAD MCQs
- PHP MCQs
- JavaScript MCQs
- jQuery MCQs
- ReactJS MCQs
- AngularJS MCQs
- JSON MCQs
- Ajax MCQs
- SASS MCQs
- HTML MCQs
- Advanced CSS MCQs
- CSS MCQs
- OOPs MCQs
- PL/SQL MCQs
- SQL MCQs
- Oracle MCQs
- SQLite MCQs
- MS Word MCQs
- Software Engineering MCQs
- Operating System MCQs
- Project Management MCQs
- Data Analytics and Visualization MCQs
- MIS MCQs
- Linux MCQs
- WordPress MCQs
- Blogging MCQs
- Marketing MCQs

- Generally Accepted Accounting Principles MCQs
- Bills of Exchange MCQs
- Business Environment MCQs
- Sustainable Development MCQs
- Marginal Costing and Absorption Costing MCQs
- Globalisation MCQs
- Indian Economy MCQs
- Retained Earnings MCQs
- Depreciation MCQs
- Partnership MCQs
- Sole Proprietorship MCQs
- Goods and Services Tax (GST) MCQs
- Cooperative Society MCQs
- Capital Market MCQs
- Business Studies MCQs
- Basic Accounting MCQs
- MIS Executive Interview Questions
- Go Language Interview Questions

Top Interview Coding Problems/Challenges!

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions!