Question

In: Computer Science

Write an ARMv8 program to sort an array of elements. As Imentioned in class, this...

Write an ARMv8 program to sort an array of elements. As I mentioned in class, this problem uses a portion of your Programming Assignment 1 where you computed the smallest and largest values in an array. Here we will extend that assignment to find the “index” of the smallest and the index of the largest elements of the array. The following C code segment illustrates how we can sort the element of an array.

For this problem, assume an array with 8 elements and test your code with the array initialized to 17, 12, 3, 7, 31, 27, 5, 19 Submit: A file containing your ARMv8 code, a read me file (if needed), a snapshot of memory showing the values in the array before your program starts execution and a snapshot of memory showing the values in the array after the program completes execution. Optional: You can include additional snapshots to show how you are using Stack, or snapshots of the array elements in between the original values and final sorted values.

You can also test and show results with different array sizes and values.

i =0;

while (i < n)

{

find_smallest (&a, i, n, index); /*returns the index of next smallest element

swap (&a, i, index); /* swap smallest with a[i]

find_largest (&a, i, n, index); /* returns the index of next largest element

swap (&v, n, index); /* swap largest with a[n]

i = i+1;

n = n-1;

}

The three functions called by above C segments are shown next.

void find_smallest (long long int *a, long long int i, long long int n, long long int index)

{

long long int smallest = a[i];

index = i;

for (j = i; j largest)

{

largest = a[j];

index = j;

}

void swap (long long int *a, long long int i, long long int j)

{

temp = a[i];

a[i] = a[j];

a[j] = temp;

}

Solutions

Expert Solution

i have code the folloing c

#include

int main()

{

int i, j, a, n, number[30];

n=8;

printf("Enter the 8 numbers \n");

for (i = 0; i < n; ++i)

scanf("%d", &number[i]);

for (i = 0; i < n; ++i)

{

for (j = i + 1; j < n; ++j)

{

if (number[i] > number[j])

{

a = number[i];

number[i] = number[j];

number[j] = a;

}

}

}

printf("The numbers arranged sortedorder are given below \n");

for (i = 0; i < n; ++i)

printf("%d\n", number[i]);

return 0;

}

armv8 code : program into Armv8 gcc 4.6.4

.LC0:

.ascii "Enter the 8 numbers \000"

.LC1:

.ascii "%d\000"

.LC2:

.ascii "The numbers arranged sortedorder are given below \000"

.LC3:

.ascii "%d\012\000"

main:

stmfd sp!, {fp, lr}

add fp, sp, #4

sub sp, sp, #136

mov r3, #8

str r3, [fp, #-16]

ldr r0, .L11

bl puts

mov r3, #0

str r3, [fp, #-8]

b .L2

.L3:

sub r2, fp, #140

ldr r3, [fp, #-8]

mov r3, r3, asl #2

add r3, r2, r3

ldr r0, .L11+4

mov r1, r3

bl scanf

ldr r3, [fp, #-8]

add r3, r3, #1

str r3, [fp, #-8]

.L2:

ldr r2, [fp, #-8]

ldr r3, [fp, #-16]

cmp r2, r3

movge r3, #0

movlt r3, #1

and r3, r3, #255

cmp r3, #0

bne .L3

mov r3, #0

str r3, [fp, #-8]

b .L4

.L8:

ldr r3, [fp, #-8]

add r3, r3, #1

str r3, [fp, #-12]

b .L5

.L7:

ldr r2, [fp, #-8]

mvn r3, #135

mov r2, r2, asl #2

sub r0, fp, #4

add r2, r0, r2

add r3, r2, r3

ldr r2, [r3, #0]

ldr r1, [fp, #-12]

mvn r3, #135

mov r1, r1, asl #2

sub r0, fp, #4

add r1, r0, r1

add r3, r1, r3

ldr r3, [r3, #0]

cmp r2, r3

ble .L6

ldr r2, [fp, #-8]

mvn r3, #135

mov r2, r2, asl #2

sub r1, fp, #4

add r2, r1, r2

add r3, r2, r3

ldr r3, [r3, #0]

str r3, [fp, #-20]

ldr r2, [fp, #-12]

mvn r3, #135

mov r2, r2, asl #2

sub r0, fp, #4

add r2, r0, r2

add r3, r2, r3

ldr r2, [r3, #0]

ldr r1, [fp, #-8]

mvn r3, #135

mov r1, r1, asl #2

sub r0, fp, #4

add r1, r0, r1

add r3, r1, r3

str r2, [r3, #0]

ldr r2, [fp, #-12]

mvn r3, #135

mov r2, r2, asl #2

sub r1, fp, #4

add r2, r1, r2

add r3, r2, r3

ldr r2, [fp, #-20]

str r2, [r3, #0]

.L6:

ldr r3, [fp, #-12]

add r3, r3, #1

str r3, [fp, #-12]

.L5:

ldr r2, [fp, #-12]

ldr r3, [fp, #-16]

cmp r2, r3

movge r3, #0

movlt r3, #1

and r3, r3, #255

cmp r3, #0

bne .L7

ldr r3, [fp, #-8]

add r3, r3, #1

str r3, [fp, #-8]

.L4:

ldr r2, [fp, #-8]

ldr r3, [fp, #-16]

cmp r2, r3

movge r3, #0

movlt r3, #1

and r3, r3, #255

cmp r3, #0

bne .L8

ldr r0, .L11+8

bl puts

mov r3, #0

str r3, [fp, #-8]

b .L9

.L10:

ldr r2, [fp, #-8]

mvn r3, #135

mov r2, r2, asl #2

sub r0, fp, #4

add r2, r0, r2

add r3, r2, r3

ldr r3, [r3, #0]

ldr r0, .L11+12

mov r1, r3

bl printf

ldr r3, [fp, #-8]

add r3, r3, #1

str r3, [fp, #-8]

.L9:

ldr r2, [fp, #-8]

ldr r3, [fp, #-16]

cmp r2, r3

movge r3, #0

movlt r3, #1

and r3, r3, #255

cmp r3, #0

bne .L10

mov r3, #0

mov r0, r3

sub sp, fp, #4

ldmfd sp!, {fp, pc}

.L11:

.word .LC0

.word .LC1

.word .LC2

.word .LC3


Related Solutions

Write a MIPS program that uses an implementation of quick sort to sort an array of...
Write a MIPS program that uses an implementation of quick sort to sort an array of numbers (Translate the following code into (Mars Assembly language). Quicksort Implementation - C int partition(int arr [] , int left , int right) { int i=left, j=right; int tmp; int pivot = arr[(left + right) / 2]; while (i <= j) { while (arr [ i ] < pivot) i ++; while (arr [ j ] > pivot) j −−; if (i <= j)...
Write a program in Java to sort the given array using merge sort, quick sort, insertion...
Write a program in Java to sort the given array using merge sort, quick sort, insertion sort, selection sort and bubble sort based on the input from the user which sorting technique they wanted to use. Get the array size, array elements from the user, and also display the sorted array along with the name of the sorting technique used.
Given the following array, write a program in C++ to sort the array using a selection...
Given the following array, write a program in C++ to sort the array using a selection sort and display the number of scores that are less than 500 and those greater than 500. Scores[0] = 198 Scores[3] = 85 Scores[6] = 73 Scores[9] = 989 Scores[1] = 486 Scores[4] = 216 Scores[7] = 319 Scores[2] = 651 Scores[5] = 912 Scores[8] = 846
Program in C: Write a program in C that reorders the elements in an array in...
Program in C: Write a program in C that reorders the elements in an array in ascending order from least to greatest. The array is {1,4,3,2,6,5,9,8,7,10}. You must use a swap function and a main function in the code. (Hint: Use void swap and swap)
ASSIGNMENT: Write a program to reverse an array and then find the average of array elements....
ASSIGNMENT: Write a program to reverse an array and then find the average of array elements. Start by creating 2 arrays that can each hold 10 integer values. Then, get values from the user and populate the 1st array. Next, populate the 2nd array with the values from the 1st array in reverse order. Then, average the corresponding elements in the 1st and 2nd arrays to populate a 3rd array (average the 1st element of the 1st array with the...
Write a program that asks the user to enter an array of random numbers, then sort...
Write a program that asks the user to enter an array of random numbers, then sort the numbers (ascending order), then print the new array, after that asks the user for a new two numbers and add them to the same array and keep the array organization. (c++ ) (using while and do while loops)
write a mips program to find the number of elements of the array that are divisible...
write a mips program to find the number of elements of the array that are divisible by 3.
Write C program that reorders elements of an array of integers such that the new order...
Write C program that reorders elements of an array of integers such that the new order is in descending order (first number being the largest). Must have a main function and a swap function. - int main() will declare an array with the values { 32, 110, 79, 18, 22, 2}. This array will be passed to the swap function. - the void swap function will perform the necessary operations to reorder the elements of the array. - After swap()...
2. Write a program in C++ that: a) Declares a 1D array A with 30 elements...
2. Write a program in C++ that: a) Declares a 1D array A with 30 elements b) Inputs an integer n from 1-30 from the keyboard. If n < 1 set n = 1. If n > 30 set n = 30. the program should keep asking the user the input n one by one, followed by printing of the value of n (n=n if bigger than 1 and smaller than 30, 1 if smaller than 1 and 30 if...
You are provided with an array of Strings and a list of Strings. Sort the elements...
You are provided with an array of Strings and a list of Strings. Sort the elements (1) in natural order, (2) in reverse natural order and (3) by the length of each String. You can fill in the details by using the following stub file: import java.util.Arrays; import java.util.Collections; import java.util.List; public class Midterm01 { public static void main(String[] args) { String[] arrayOfCities = { "Atlanta", "Savannah", "New York", "Dallas", "Rio" }; List<String> listOfCities = Arrays.asList("Atlanta", "Savannah", "New York", "Dallas",...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT