Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

-####################################################################### lab04 # - In second part of your program, main should use a loop # repeatedly ask user to input a number, call subprogram

-#######################################################################

lab04

# - In second part of your program, main should use a loop

# repeatedly ask user to input a number, call subprogram

# array_contains to see whether the array contains this

# number, and print out the index of the number after

# return. The loop should end if user input -1. array_contains

# will take 3 arguments IN (array base address, array

# length, and user input number) and 1 argument OUT (index

# of the number if array contains the number, -1 if not).

#

# - In third part of your program, main should use another

# loop ask user to input an index (0 <= index < 10), and

# call print_nth to locate and print the element at that

# index. Again, loop should end if user input -1. You

# should print an error message if user input an invalid

# index. print_nth will take 2 arguments IN (array base

# address, and user input index) and no argument out.

#######################################################################

# search_array

#

# This subprogram will take 3 arguments IN and 1 argument OUT:

# - array base address (argument IN)

# - array length (argument IN)

# - search number (argument IN)

# - index of the number (argument OUT)

#

# It will iterate through the array to see whether the array

# contains the passed in number.

# - If yes, this subprogram will return the index of that

# number

# - If no, this subprogram will return -1.

#

#######################################################################

# Arguments IN and OUT

#

# $a0 array base address

# $a1 array length

# $a2 user input number

# $a3

# $v0 index of the number, -1 if not exist

# $v1

#######################################################################

# Register Usage

#

# $t0 base address

# $t1 array length

# $t2 user input number

# $t3 counter

# $t4 current element

# $t5

# $t6

# $t7

# $t8

# $t9 counter

#######################################################################

.data

#######################################################################

.text

array_contains:

# TODO: write this subprogram

jr $ra # return to main

#######################################################################

#######################################################################

# print_nth

#

# This subprogram will take 2 arguments IN and no argument OUT:

# - array base address

# - user input index

#

# it will calculate the address of the element at that index

# using equation: address = base address + index * size

# then load the element from memory and print to console.

#######################################################################

# Arguments IN and OUT

#

# $a0 array base address

# $a1 user input index

# $a2

# $a3

# $v0

# $v1

#######################################################################

# Register Usage

#

# $t0 array base address

# $t1 user input index

# $t2 temp register to calculate address

# $t3 element at the index

# $t4

# $t5

# $t6

# $t7

# $t8

# $t9

#######################################################################

.data

print_nth_p: .asciiz "The number at index "

print_nth_is_p: .asciiz " is: "

#######################################################################

.text

print_nth:

# TODO: write this subprogram

jr $ra # return to main

#######################################################################

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions