MIPS Assembly
The program:
Write a function in
MIPS assembly
that takes an array of integers and finds local minimum points. i.e., points that if the input entry is smaller than both adjacent entries. The output is an array of the same size of the input array. The output point is 1 if the corresponding input entry is a relative minimum, otherwise 0. (You should ignore the output array's boundary items, set to 0.)
My code:
# (Note: The first/last entry of the output array is always 0
# since it's ignored, never be a local minimum.)
# $a0: The base address of the input array
# $a1: The base address of the output array with local minimum points
# $a2: Size of array
find_local_minima:
############################ Part 2: your code begins here ###
la $t1, ($t2)
la $t1, ($t2)
move $a1, $s0
li $a2, 4
jal find_local_minima
print:
ble $a2, 0, exit
lw $a0, ($s0)
li $v0, 1
syscall
addi $s0, $s0, 4
addi $a2, $a2, -1
############################ Part 2: your code ends here ###
jr $ra
I am not getting the correct output - attached
Extracted text: Expected output: 0, 0, 1, 0, 0, 1, 0, 0 Obtained output: 0, 0, 0, 0, 0, 0, 0, 0