+1  A: 

It has been a very long time since I have written any assembly code but the questions seems more philosophical. Without knowing the larger goals here are some ideas.

Converting every key as they are entered: Many times the program needs to respond to individual key strokes as the program is running, (ie dynamic commands, up, down, left etc.). In this case, the key strokes should be converted individually. Other times, a block of data or strings need to be converted and this operation is usually done at the conclusion of the enter key of is a larger block of data. These cases require the characters to be “looped” through and converted.

However, in either case the “work” should done in a generic subroutine that can be called from either type of situation.

I hope this helps,

Ed

+1  A: 

You can simply xor the character with itself shifted right one place to get the Gray representation, no loop needed. Example when your character is in AL :

mov bl, al
shr bl, 1
xor al, bl

AL is now the Gray-code representation.

In C this would be :

c^=c>>1;

To go back to the binary representation you can xor the Gray-code with it self, shifted right by decreasing powers-of-2, starting with the largest power-of-2 which is smaller than the data size, eg:

mov bl, al
shr bl, 4
xor al, bl
mov bl, al
shr bl, 2
xor al, bl
mov bl, al
shr bl, 1
xor al, bl

In C this would be :

c^=c>>4; c^=c>>2; c^=c>>1;
matja