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) 

AddressData
.
.
.
.
.
.
8200EB
.
.
.
.
.
.

Program

AddressHEX CodesLabelsMnemonicsComments
80003A, 00, 82START: LDA 8200 H A = (8200 H); load the gray code
800357
MOV D, A D = A
80040E, 07
MVI C, 07 H C = 07 H
800637UP: STC Cy = 1
80073F
CMC Cy = 0; Clear Cy
80081F
RAR Rotate Right with carry
8009AA
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
801176
HLT Stop

Output

AddressData
.
.
.
.
.
.
8201B2
.
.
.
.
.
.

Updated on: 30-Jul-2019

866 Views

Kickstart Your Career

Get certified by completing the course

Advertisements