##################### #a0: input buffer address #a1: output buffer address #a2:
ID: 3743487 • Letter: #
Question
#####################
#a0: input buffer address
#a1: output buffer address
#a2: number of elements in array
#####################
find_maxima:
############## your code begins here #################
############## your code ends here ##################
jr $ra
8. Write a function which takes an array of integers and finds local maxima points. i.e., points that are bigger than both adjacent elements. The output is an array with same size in which elements are one, if the corresponding input point is a relative maximum otherwise zero. (You should ignore the array boundary items.)Explanation / Answer
### Comment if u have any doubt ######
la $t1,$a1 # initial offset of Input array
la $t2,$a1 # initial offset of Output array
lw $t3,$a2 # get size of list
li $t4,1 # set loop coumter
Loop:
bgt $t4,$t3, loop_end # stop looping after last element
beq $t4,0,copy_boundary_element
beq $t4,$t3,copy_boundary_element
addi $t1,$t1,-4
lw $t6,$t1 # previous value = array-4
addi $t1,$t1,4
lw $t7,$t1 #current value = (array-4) + 4
blt $t7,$t6,putZer0
addi $t1,$t1,4
lw $t6,$t1 #next value = ((array-4) + 4) + 4
blt $t7,$t6,putZer0
putOne:
li $t0,1
sw $t0,$t2 # store 1 in output array
J IncrementAddress # jump unconditionally
putZero:
li $t0,0
sw $t0,$t2 # store 0 in output array
J IncrementAddress # jump unconditionally
copy_boundary_element :
lw $t6,$t1 # store boundary elements
sw $t6,$t2
IncrementAddress :
addi $t1,$t1,4 # input array address increment
addi $t2,$t2,4 # output array address increment
addi $t4,$t4,1 #increment counter
beq $t0,$t0,Loop
loop_end :
jr $a1
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.