Question: **PLEASE HELP ME TO FINISH THIS PROGRAM IN MARS MIPS 4.5 ASSEMBLY** This program declares an array of 7 integers in the data section. Each
**PLEASE HELP ME TO FINISH THIS PROGRAM IN MARS MIPS 4.5 ASSEMBLY**
This program declares an array of 7 integers in the data section. Each integer is a word in size. A function called find42 is defined in the code which called from main. The find42 function implements a loop which goes through the array of integers looking for the specific value 42. It returns the index of the number 42 if it is found, or the value -1 if 42 is not there in the array.
Specification of what you need to do: In the associated file, the 7 integers of the array are given different values in the data section. You must first change all those values to 0 in the data section. Next, implement a loop within the main function that assigns 7 integer values taken as inputs from the user, to the 7 locations of the array. After that loop ends, take one more integer input from the user - this value should be the value to find (not the fixed value 42 as in the associated code file). Next call the function findN, where the function find42 should be replaced by findN. The findN function must return the index of the number N if it is found, or the value -1 if N is not there in the array. Here N is the value to search for.
# Functional Description: # This program searches for the number 42 in an array of integers. # Returns the index where 42 is found or returns -1 if not found. ##################################################################### .data array: .word 10, -2, 34, 110, 42, 55, 725 size: .word 7 outstr: .asciiz "The index found is " .text main: lw $a1, size la $a0, array jal find42 move $t0, $v0 # save the returned index value in $t0 la $a0, outstr # load the addr of outstr into $a0 li $v0, 4 # 4 is the print_string syscall syscall # print the prompt move $a0, $t0 # load the index value into $a0 li $v0, 1 # 4 is the print integer syscall syscall # print the integer li $v0, 10 syscall find42: addi $t0, $0, 0 # $t0 = i = 0 addi $t1, $0, 42 # $t1 = 42 loop: slt $t3, $t0, $a1 # $t3 = 1 if i < size (not at end of array) beq $t3, $0, exit # if reached end of array, return -1 sll $t2, $t0, 2 # $t2 = i*4 add $t2, $t2, $a0 # $t2 = address of array[i] lw $t2, 0($t2) # $t2 = array[i] beq $t2, $t1, done # $t2 == 42? addi $t0, $t0, 1 # i = i + 1 j loop done: add $v0, $t0, $0 # $v0 = i jr $ra exit: addi $v0, $0, -1 # $v0 = -1 jr $ra
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
