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 –

  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 –

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 –

  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

This article is attributed to GeeksforGeeks.org

You Might Also Like

leave a comment



load comments

Subscribe to Our Newsletter