Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write it in java then in assembly 3.Consider an array A of size 5 and containing

ID: 3909221 • Letter: W

Question

write it in java then in assembly

3.Consider an array A of size 5 and containing the integers 33, 20, 18, 45, and 100 respectively Wire an Assembly code that sorts this array in an ascending manner and stores the sorted integers in anew array B that is, the elements of A remain in their same order). The elements of B are then divided by 100. Keep in mind that you can use within your code any assembly instruction that is supported by assembler regardless of whether it is being used in the course (i.e. mul, div, etc.) 4. Run and test your code.

Explanation / Answer

Java

public class Sort {
public static void main(String args[]) {
int[] a = { 33,20,18,45,100 };
int[] b = new int[5];
int i;
  
for(i =0; i<5; i++) // copying array
{
b[i]=a[i];
  
}
  
for(i=0;i<4;i++) // sorting the array
{
int min_idx = i;
for (int j = i+1; j < 5; j++)
if (b[j] < b[min_idx])
min_idx = j;

int temp = b[min_idx];
b[min_idx] = b[i];
b[i] = temp;
}
for (i=0; i<5; i++)
System.out.print(b[i]+" ");
System.out.println();
}
}

Output  18 20 33 45 100

Assembly Language

/* sorting the array */