Assembly Programming Language using Visual Studio May be co
Assembly Programming Language using Visual Studio - May be completed in either 32-bit mode or 64-bit mode
Exchanging Pairs of Array Values
Write a program with a loop and 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.
Solution
push rbp
 mov rbp, rsp
 mov DWORD PTR [rbp-48], 1
 mov DWORD PTR [rbp-44], 4
 mov DWORD PTR [rbp-40], 45
 mov DWORD PTR [rbp-36], 6
 mov DWORD PTR [rbp-32], 10
 mov DWORD PTR [rbp-28], 8
 mov DWORD PTR [rbp-4], 6
 mov DWORD PTR [rbp-8], 0
 .L3:
 mov eax, DWORD PTR [rbp-8]
 cmp eax, DWORD PTR [rbp-4]
 jge .L2
 mov eax, DWORD PTR [rbp-8]
 cdqe
 mov eax, DWORD PTR [rbp-48+rax*4]
 mov DWORD PTR [rbp-12], eax
 mov eax, DWORD PTR [rbp-8]
 add eax, 1
 cdqe
 mov edx, DWORD PTR [rbp-48+rax*4]
 mov eax, DWORD PTR [rbp-8]
 cdqe
 mov DWORD PTR [rbp-48+rax*4], edx
 mov eax, DWORD PTR [rbp-8]
 add eax, 1
 cdqe
 mov edx, DWORD PTR [rbp-12]
 mov DWORD PTR [rbp-48+rax*4], edx
 jmp .L3
 .L2:
 mov eax, 0
 pop rbp
 ret

