Open In App

8085 program to convert gray to binary

Improve
Improve
Like Article
Like
Save
Share
Report

Problem – Write an assembly language program in 8085 microprocessor to convert gray numbers to binary. Example – Algorithm –

Gray-to-BInary

  1. Load the data from address 2050 in A
  2. Move the data 07 in C
  3. Move the data of A to B
  4. Extract the MSB (Most Significant Bit) of data available in A
  5. Rotate the bits of A to right
  6. Take AND between data in A and 7F
  7. Take XOR between the data present in A and B
  8. Decrements the contents of C
  9. If Zero Flag (ZF) is not set go to step 4 else go to step 9
  10. Store the result at memory address 3050
  11. Stop

Program –

MEMORY ADDRESS MNEMONICS COMMENT
2000 LDA 2050 A <- 2050
2003 MVI C, 07 C <- 07
2005 MOV B, A B <- A
2006 ANI 80 A = A AND 80
2008 RRC Rotate A to Right without carry
2009 ANI 7F A = A AND 7F
200B XRA B A = A XOR B
200C DCR C C = C – 1
200D JNZ 2008 JUMP to 2008 if ZF = 0
2011 STA 3050 3050 <- A
2014 HLT Stop

Explanation–

  1. LDA 2050 is used to load the data from address 2050 in A
  2. MVI C, 07 is used to move the data 07 in C
  3. MOV B, A moves the data of A to B
  4. ANI 80 extracts the MSB(Most Significant Bit) of data available in A
  5. RRC rotates the bits of A to right without carry
  6. ANI 7F is used to tTake AND between data in A and 7F
  7. XRA B takes XOR between the data present in A and B
  8. DCR C is used to decrement the contents of C
  9. JNZ 2008 is used to jump to address 2008 if ZF = 0
  10. STA 3050 is used to store the result at memory address 3050
  11. HLT is used to end the program

Advantages:

Simplification: A binary image contains only two color values (typically black and white), which can simplify image analysis and processing tasks. This can be especially useful in applications such as optical character recognition (OCR) or image segmentation.
Reduced storage requirements: Since a binary image contains only two color values, it requires less storage space than a grayscale or color image.
Easy visualization: Binary images can be easily visualized and understood by humans, since they only contain two color values.
 

Disadvantages:

Loss of information: When converting a grayscale image to binary, some information is lost, as the various shades of gray in the original image are reduced to just two values. This can affect the accuracy of certain image analysis tasks.
Threshold selection: Converting a grayscale image to binary requires selecting a threshold value, which can be challenging. Choosing the wrong threshold can result in a binary image that does not accurately represent the original grayscale image.
Sensitivity to lighting conditions: Binary images are highly sensitive to lighting conditions, and small changes in lighting can cause significant changes in the resulting binary image. This can make it difficult to use binary images in applications where lighting conditions may vary.


Last Updated : 22 Mar, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads