Search code examples
assemblyx86swap

How to swap a 16bit Value with x86 Assembler?


Hi I want to swap a 16 bit value. In in an other question someone suggested the following solution. But this only works with immidiate values,

mov  eax, 0AABBCCDDh
xchg  ah, al
ror   eax, 16
xchg  ah, al.

But this only works with immidiate values. Is there a solution, where I can swap a 16 bit value which is in a register?

Edit: With swap I mean 0xAFBA -> 0xBAFA


Solution

  • With swap I mean 0xAFBA -> 0xBAFA

    mov   ax, 0xAFBA
    xchg  al, ah
    ror   al, 4
    

    AX now holds 0xBAFA