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 Accumulator
- Reset carry flag i.e. CY = 0
- Rotate the contents of Accumulator right by 1 bit with carry and perform xor operation with initial value of input
- Store the result at memory location 3050
Program –
| MEMORY ADDRESS | MNEMONICS | COMMENT |
|---|---|---|
| 2000 | LDA 2050 | A <- M[2050] |
| 2003 | MOV B, A | B <- A |
| 2004 | STC | CY = 1 |
| 2005 | CMC | CY <- complement of CY |
| 2006 | RAR | Rotate 1 bit right with carry |
| 2007 | XRA B | A <- A XOR B |
| 2008 | STA 3050 | M[3050] <- A |
| 200B | HLT | End of program |
Explanation –
- LDA 2050 loads the content of memory location 2050 in accumulator
- MOV B, A transfers the content of register A in register B
- STC sets the carry flag i.e. CY becomes 1
- CMC complements the carry flag i.e. CY becomes 0
- RAR rotate the content of accumulator by 1 bit along with carry flag
- XRA B performs the xor operation in values of register A and register B and store the result in A
- STA 3050 stores the value of accumulator in memory location 3050
- HLT stops executing the program and halts any further execution
Recommended Posts:
- 8085 program to convert an 8 bit BCD number into hexadecimal number
- 8085 program to convert a BCD number to binary
- 8085 program to convert 8 bit BCD number into ASCII Code
- 8085 program to convert a hexadecimal number into ASCII code
- 8086 program to convert binary to Grey code
- 8085 program to count number of ones in the given 8-bit number
- 8085 program to reverse 16 bit number
- 8085 program to reverse 8 bit number
- 8085 program to check whether the given number is even or odd
- 8085 program to find sum of digits of 8 bit number
- 8085 program to find 1's and 2's complement of 8-bit number
- 8085 program to check whether the given 16 bit number is palindrome or not
- 8085 program to find nth power of a number
- 8085 program to find the factorial of a number
- 8085 program to determine if the number is prime or not
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.

