Please do both questions in MASM and complete these two in two separate files.
Write a program with an 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.
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
.data
array DWORD A,B,C,D
.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
Get Answers For Free
Most questions answered within 1 hours.