proc Bin2Grey, Bin

enter
mov eax, [Bin]
shr eax, 1
xor eax, [Bin]
return
Code used to test it with debug


; Assume ax==0 and bx==0
Main: inc ax
jz Done ; Done (0xFFFF -> 0x0000)
mov cx, bx ; Save bx for test
mov bx, ax
shr bx, 1
xor bx, ax ; Grey Code = ax xor (ax >> 1)
xor cx, bx ; cx = Bit Mask Difference

OneBit:
rcr cx, 1 ; Do bit test with Carry Flag
jnc OneBit ; Find a Bit?
jcxz Main ; Yes -- Any More bits?
or ax, -1 ; Yes -- Return -1 in ax

Done:
int 3
Posted on 2002-08-21 03:14:48 by eet_1024