8085 Program to Convert Gray to Binary



Now let us see a program of Intel 8085 Microprocessor. This program will convert gray code to binary code.

Problem Statement

Write an assembly language program for 8085 to convert gray code to binary code. The data is stored at address 8200H & store the result at memory location 8201H.

Discussion

Here we are loading the number from memory and in each step we are performing right shift, and XOR the intermediate result with the previous one. Thus we are getting the result. In the following demonstration you can get the logic.

C       1110 1011    (A) (EBH)
07H     0111 0101    (RAR)
XOR     1110 1011    (D)
        1001 1110    (A = A XOR D) (9EH)
06H     0100 1111    (RAR)
XOR     1110 1011    (D)
        1010 0100    (A = A XOR D) (A4H)
05H     0101 0010    (RAR)
XOR     1110 1011    (D)
        1011 1001    (A = A XOR D) (B9H)
04H     0101 1100    (RAR)

XOR     1110 1011   (D)

        1011 0111    (A = A XOR D) (B7H) 03H     0101 1011    (RAR) XOR     1110 1011    (D)         1011 0000    (A = A XOR D) (B0H) 02H     0101 1000    (RAR) XOR     1110 1011    (D)         1011 0011    (A = A XOR D) (B3H) 01H     0101 1001    (RAR) XOR     1110 1011    (D)         1011 0010    (A = A XOR D) (B2H) 

Input

Address Data
.
.
.
.
.
.
8200 EB
.
.
.
.
.
.


Flow Diagram

Program

Address HEX Codes Labels Mnemonics Comments
8000 3A, 00, 82 START:  LDA 8200 H  A = (8200 H); load the gray code
8003 57
MOV D, A  D = A
8004 0E, 07
MVI C, 07 H  C = 07 H
8006 37 UP:  STC  Cy = 1
8007 3F 
CMC  Cy = 0; Clear Cy
8008 1F 
RAR  Rotate Right with carry
8009 AA 
XRA D  A = A XOR D
800A  0D 
DCR C  C = C – 1
800B  C2, 06, 80
JNZ UP  Is C = 0? If no go to up
800E  32, 01, 82
STA 8201 H  (8201 H) = A; store the number
8011 76
HLT  Stop


Output

Address Data
.
.
.
.
.
.
8201 B2
.
.
.
.
.
.
Updated on: 2019-07-30T22:30:24+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements