;according to http://en.wikipedia.org/wiki/Gray_code
;
; Let G[n:0] be the input array of bits in Gray code
; Let B[n:0] be the output array of bits in the usual binary representation
;   B[n] = G[n]
;   for j = n-1 downto 0
;     B[j] = B[[j+1] XOR G[j]


       DSEG   AT   30h
       
G:  DS     3

       CSEG
       
Gray24_Bin:
       
       mov    r2, #25
G24BLoop:
       mov    a, G+0
       rlc    a
       mov    G+0, a
       mov    a, G+1
       rlc    a
       mov    G+1, a
       mov    a, G+2
       rlc    a
       mov    G+2, a
       djnz   r2, G24BLoop1
       sjmp   G24BLoopEnd
G24BLoop1:
       clr    a
       rrc    a      
       xrl    G+2, a
       rlc    a
       sjmp   G24BLoop
G24BLoopEnd:

;that's all, folks. But let's just make a test, a B->G conversion, to verify
       clr    c
       mov    a, G+2
       rrc    a
       xrl    G+2, a
       mov    a, G+1
       rrc    a
       xrl    G+1, a
       mov    a, G+0
       rrc    a
       xrl    G+0, a
;... and by here whe should have the original number in G
       
       end
