Question: Write a MIPS assembly language program to sequentially search an array to find the index of the specified target value. If the target value is

Write a MIPS assembly language program to sequentially search an array to find the index of the specified target value. If the target value is not in the array, the non-existent index of -1 should be used to set foundIndex.

Your .data section should be as shown below with the foundIndex being set to 6 as the program runs:

data array: .word 20, 30, 10, 40, 50, 60, 35, 25, 15, 5

target: .word 35

foundIndex: .word 0

length: .word 10 # number of items actually in the array

.text

.globl main

main: # MIPS Assembly language program here li $v0, 10 # system call to exit the program syscall

The high-level language algorithm for sequential search that I want you to implement is:

index = 0

while index < length and array[index] target do

index = index + 1

end while

if index < length then

foundIndex = index

else

foundIndex = -1 end if

Extra Credit: Implement the sequential search algorithm by walking pointers.

This is what I have so far:

.data array: .word 20, 30, 10, 40, 50, 60, 35, 25, 15, 5 target: .word 35 foundindex: .word 0 length: .word 10

.text .globl main

main: li, $2, 0 lw, $3, length lw, $4, array lw, $5, target lw, $7, foundindex while: mul, $6, $2, 4 add, $6, $4, $6 lw, $6, 0($6) bge, $2, $3, end_while beq, $6, $5, end_while add, $2, $2, 1 j while end_while: if: bge $2, $3, else move, $7, $2 j end_if else: add, $7, $7, -1 end_if: li $v0, 10 syscall

If you could edit the code and make this program work correctly and give me the desired output that would be great! I don't need a whole bunch of fancy outputing I just need the simulater to get the right number in the end! Thanks in advance!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!