Question

In: Computer Science

implement in LEGV8 find the smallest value in an array.

implement in LEGV8 find the smallest value in an array.

Solutions

Expert Solution

Solution:

I am using following registers to hold corresponding values :

X9 : i

X22 : smallest value

X20 : base address of array

X19 : n

*************************************************
           LDUR X22, [ X20, #0 ] // Load first element in X22
           ADDI X9, X9, #0 //load i=0 for while loop
           ADDI X8, X8, #0 //load j=0 for accessing array elements
   Loop :SUB X10, X19, X9 //check condition for while loop termination
           CBZ Exit
           LSL X11, X8, #3 // lsft shift j by 3 to get next elements base address
           ADD X11, X11, X20 // get &a[i]
           LDUR X12, [ X11, #0] //get a[i] in X12
           SUBS X13, X22, X12 //check if a[i]<smallest
           B.LE Next_
           LDUR X22, X12 //if a[i] < smallest, load in X22 and loop again
           B
   Next_ :   B //loop again

Please give thumbsup, if you like it. Thanks.


Related Solutions

Implement a recursive binary search on an array of 8-byte integers in LEGV8
Implement a recursive binary search on an array of 8-byte integers in LEGV8
Given an array of numbers, find the index of the smallest array element (the pivot), for...
Given an array of numbers, find the index of the smallest array element (the pivot), for which the sums of all elements to the left and to the right are equal. The array may not be reordered. Example arr=[1,2,3,4,6] the sum of the first three elements, 1+2+3=6. The value of the last element is 6. Using zero based indexing, arr[3]=4 is the pivot between the two subarrays. The index of the pivot is 3. Function Description Complete the function balancedSum...
Declare a 3x4 multidimensional array. Receive values for eachelement from user. Find the smallest value...
Declare a 3x4 multidimensional array. Receive values for each element from user. Find the smallest value in the multidimensional array, display its index and value, use array access operator [ ]. Find the largest value in the multidimensional array, display its index and value, use pointers. Write C code.
Use C Programming - Given an array of integers and a number K, find the smallest...
Use C Programming - Given an array of integers and a number K, find the smallest element in array greater than or equal to K. If such element exists in the array, display it otherwise display "-1". Example: Input:     8     1 3 4 7 8 9 9 10     5     where: First line represents the number of elements in the array. Second line represents the elements in the array. Third line represents the value of K. Output:     7 Explanation:...
In Java Find the second largest and second smallest element in a given array. You can...
In Java Find the second largest and second smallest element in a given array. You can hardcode/declare the array in your program.
You'll implement a completely generic version of an algorithm to find the maximum of an array....
You'll implement a completely generic version of an algorithm to find the maximum of an array. Unlike in the past, when our algorithm only worked for int[] or double[], this version will work on any Java objects that are comparable, specifically any Java object that implements the Comparable interface. Create a public class named Max with a single class method named max. max should accept an array of Objects that implement Comparable and return the maximum. If the array is...
implement please... ........................................... public class TernarySearch {     /** Task: Searches for a value in an array....
implement please... ........................................... public class TernarySearch {     /** Task: Searches for a value in an array.      * @param a an array of Comparable objects      * @param desiredItem an item to search for         * @param n an integer > 0      */     public static <T extends Comparable<? super T>>     boolean ternarySearch(T[] a, T desiredItem, int n)     {         // it is assumed that the data is already sorted         return ternarySearch(a, 0, n-1, desiredItem);     } // end ternarySearch     /** Task: recursive ternarySearch search through...
If P713 is divisible by 11, find the value of the smallest natural number P?
If P713 is divisible by 11, find the value of the smallest natural number P?
Create an array of 10,000 elements, use sorted, near sorted, and unsorted arrays. Implement find the...
Create an array of 10,000 elements, use sorted, near sorted, and unsorted arrays. Implement find the kth smallest item in an array. Use the first item as the pivot. Compare sets of results using a static call counter. Reset counter before running another search. Create a Test drive to exhaustively test the program. // Assume all values in S are unique. kSmall(int [] S, int k): int (value of k-smallest element) pivot = arbitrary element from S:  let’s use the first...
Using Java Write a method that returns the index of the smallest element in an array...
Using Java Write a method that returns the index of the smallest element in an array of integers. If the number of such elements is greater than 1, return the smallest index. Use the following header:   public static int indexOfSmallestElement (double[] array)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT