- Swap elements in array, e[0] with e[1], e[2] with e[3] and so on. Need to read more on faster xchg instruction, xor?
var dd 1,2,3,4,5,6,7,8
mov esi, OFFSET var
mov ecx, LENGTHOF var / 2 ; processing 2 elements at one time
xchgloop:
mov eax, DWORD PTR [esi] ; eax=1
xchg eax, DWORD PTR [esi+4] ; put 1 in esi+4 and put [esi+4] in eax
mov DWORD PTR [esi], eax ; put [esi+4] in esi+0
add esi, TYPE var * 2 ; move to next 2 elements