Question

# Given the following array named 'array1': array1 DWORD 50h, 51h, 52h, 53h Write instructions to swap...

Given the following array named 'array1':

array1 DWORD 50h, 51h, 52h, 53h

Write instructions to swap the items in array1 (using only MOV and XCHG instruction), so that the array1 become:

53h, 51h, 50h, 52h

( That means the first item in the array is 53h, second item is 51h, third item is 50h, forth item is 52h).

You can use registers to perform the MOV and XCHG operation.

Write the code to perform above mentioned transformation.

#include <stdio.h>

int main()
{
//Initialize array
int arr[] = { 50, 51, 52, 53};

//Calculate length of array arr
int length = sizeof(arr)/sizeof(arr[0]);

printf("Original array: \n");
for (int i = 0; i < length; i++) {
printf("%d ", arr[i]);
}

printf("\n");

printf("Array in reverse order: \n");
//Loop through the array in reverse order
for (int i = length-1; i >= 0; i--) {
printf("%d ", arr[i]);
}
return 0;
}

#### Earn Coins

Coins can be redeemed for fabulous gifts.