Write a program with a loop with indexed addressing that exchanges every pair of values in an array with an even number of elements. Therefore, item i will exchange with item i + 1, and item i + 2 will exchange with item i + 3, and so on. Example: [1,2,3,4,5,6,7,8] → [2,1,4,3,6,5,8,7]
.386 .model flat,stdcall .stack 4096 ExitProcess proto,dwExitCode:dword .data array DWORD 1,2,3,4,5,6,7,8 .code main proc ; must offset the array so that esi regester ; holds the address of the first item in the array mov esi, OFFSET array ; ecx register is now 4 mov ecx, LENGTHOF array / 2 myLoop: ; will loop 4 times because ecx has 4 ; get the pair numbers from array mov eax, [esi] mov ebx, [esi + 4] ; swap the pairs in array mov [esi], ebx mov [esi + 4], eax ; A DWORD is 4 bytes so we must increment the ; esi register by 8 to get the next pair. add esi, TYPE array * 2 loop myLoop invoke ExitProcess,0 main endp end main