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.
Find the K'th smallest element in an unsorted array of integers. Find the K'th largest element...
Find the K'th smallest element in an unsorted array of integers. Find the K'th largest element in an unsorted array of integers. please make two separate methods in java
Develop a recursive algorithm to find the smallest and largest element in an array and trace...
Develop a recursive algorithm to find the smallest and largest element in an array and trace the recursive function with appropriate message. using c++ add comment to the 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:...
find the k-th smallest value given array[ 5, 2, 1, 15, 6, 9, 3, 4, 11]...
find the k-th smallest value given array[ 5, 2, 1, 15, 6, 9, 3, 4, 11] , k=2, the algorithm return the first two value: 1, 2 please show steps of how to output the first 2 values by using merge sort and please analyze the running time. your time is greatly appreciated.
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.
In python please :) How to get the n th smallest even value of given array?...
In python please :) How to get the n th smallest even value of given array? (Use for loop for this problem. Do not use existing codes. Use your own codes). For example, in given list [11,23,58,31,56,22,43,12,65,19], if n is defined as 3. The program will print 56. (By using for loop and obtain the set of evens. By using another for loop, from the set of evens remove (n-1) observations and break the loop and find the minimum observation...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT