Jump to content

Xor swap algorithm/Assembler Code

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Rlee0001 (talk | contribs) at 21:11, 9 November 2002 (some explaination, needs copyediting.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The following routine swaps the value in the AX register with the value in the BX register without using a temporary buffer.


           XOR         AX, BX
           XOR         BX, AX
           XOR         AX, BX


The Intel 80386 CPU also supports an XCHG instruction which does the same work on its operands more efficiently then the above routine. This instruction is not supported by the original 8086, 8088, 80186 and 80286 CPUs however.

See: Xor swap algorithm