In: Computer Science
implement in LEGV8 find the smallest value in an array.
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.