Open In App
Related Articles

8085 program to convert an 8 bit number into Grey number

Like Article
Save Article
Report issue

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 –

  1. Load the content of memory location 2050 in Accumulator
  2. Reset carry flag i.e. CY = 0
  3. Rotate the contents of Accumulator right by 1 bit with carry and perform xor operation with initial value of input
  4. Store the result at memory location 3050

Program –

2000LDA 2050A <- M[2050]
2003MOV B, AB <- A
2004STCCY = 1
2005CMCCY <- complement of CY
2006RARRotate 1 bit right with carry
2007XRA BA <- A XOR B
2008STA 3050M[3050] <- A
200BHLTEnd of program

Explanation –

  1. LDA 2050 loads the content of memory location 2050 in accumulator
  2. MOV B, A transfers the content of register A in register B
  3. STC sets the carry flag i.e. CY becomes 1
  4. CMC complements the carry flag i.e. CY becomes 0
  5. RAR rotate the content of accumulator by 1 bit along with carry flag
  6. XRA B performs the xor operation in values of register A and register B and store the result in A
  7. STA 3050 stores the value of accumulator in memory location 3050
  8. HLT stops executing the program and halts any further execution


  1. Reduced error rate: Gray code can reduce the error rate when transmitting or storing data, since only one bit changes between adjacent values. This can be useful in applications where errors must be minimized, such as in digital communications.
  2. Improved accuracy: Gray code can improve the accuracy of position or distance measurements, since small changes in position result in small changes in the Gray code value.
  3. Used in digital electronics: Gray code is commonly used in digital electronics, particularly in applications such as rotary encoders or optical sensors.


  1. Limited range: Gray code has a limited range compared to binary code, which can make it unsuitable for certain applications where a wide range of values is required.
  2. Non-intuitive ordering: As mentioned earlier, the ordering of Gray code values may be non-intuitive, making it more difficult for humans to understand or interpret them.
  3. Complex conversion: Converting between binary and Gray code can be more complex than converting between binary and other number systems, which can make it more difficult to work with Gray code values.

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