Skip to content
Related Articles

Related Articles

8085 program to convert binary numbers to gray

View Discussion
Improve Article
Save Article
  • Last Updated : 22 May, 2018
View Discussion
Improve Article
Save Article

Prerequisite – Binary to/from Gray Code
Problem – Write an assembly language program in 8085 microprocessor to convert binary numbers to gray.

Example –

Algorithm –

  1. Set the Carry Flag (CY) to 0.
  2. Load the data from address 2050 in A.
  3. Move the data of A(accumulator) into register B.
  4. Rotate the bits of A to right.
  5. XOR the contents of register A and B.
  6. Store the result at memory address 3050.
  7. Stop.

Program –

MEMORY ADDRESSMNEMONICSCOMMENT
2000STCCY <- 1
2001CMCCY <- 1's Compliment of CY
2002LDA 2050A <- 2050
2005MOV B,AB <- A
2006RARRotate accumulator right with carry
2007XRA BA = A XOR B
2008STA 30503050 <- A
200BHLTStop

Explanation –

  1. STC is used to set carry flag (CY) to 1.
  2. CMC is used to take 1’s compliment of the contents of carry flag (CY).
  3. LDA 2050 is used load the data from address 2050 in A.
  4. MOV B, A is used to move the data of A into B.
  5. RAR is used to rotate the bits of A along with carry flag (CY) to right one time.
  6. XRA B is used to perform XOR operation between the contents of register A and B.
  7. STA 3050 is used to store the contents of A to 3050.
  8. HLT is used end the program.
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!