Question: Visual studio is the compiler. This is a x86 assembly program. In this lab we will write an assembly program that uses loops with indirect
Visual studio is the compiler. This is a x86 assembly program.
In this lab we will write an assembly program that uses loops with indirect or indexed addressing to permutates (re-arranges) an integer array. The following example shows how an array is re-arranged based on the permutation:
| Position/Index: |
Array before permutation:
0 1 2 3 4 5 6 7 8 9
| 12 | 9 | 54 | 20 | 3 | 38 | 72 | 17 | 91 | 25 |
Permutation:
| 8 | 3 | 5 | 9 | 2 | 6 | 0 | 4 | 1 | 7 |
Array after permutation:
| 91 | 20 | 38 | 25 | 54 | 72 | 12 | 3 | 9 | 17 |
In your program you are allowed to define only two arrays one for the array and the other for the permutation. Do not copy the array elements to any other array! The runtime screen shot can be as follows (you can use different numbers):
|
|
Welcome! This program permutates an array of any size.
Please enter the size of the array: 10
Please enter the 10 elements of your array:
12 9 54 20 3 38 72 17 91 25
Please enter the permutation:
8 3 5 9 2 6 0 4 1 7
The array after permutation is:
91 20 38 25 54 72 12 3 9 17
Hint:
The following algorithm gives one possible solution to the problem
Enter array size as SIZE;
for i from 0 to (SIZE - 2)
Array[i] <-> Array[Permutation[i]];
for j from (i+1) from (SIZE 1)
if (i == permutation[j])
permutation[i] <-> permutation[j];
break;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
