Fast Nibble swapAssembler/80286

Sometimes it might be usefull to swap all the nibbles in a register. The shortest way to swap the two lower nibbles in a register is a single instruction:
        rol     al,4
To swap all four pairs of nibbles:
;
; fast nibble swapping
;
; input:
;   eax = word to nibble swap
;
; output:
;   eax = nibble swapped word
;
; destroys:
;   edx
;   flags
;

        mov     edx,eax
        shr     eax,4
        and     edx,0f0f0f0fh
        shl     edx,4
        and     eax,0f0f0f0fh
        or      eax,edx
Gem writer: Terje Mathisen
last updated: 1998-03-16