Question: Find all the obvious bugs and correct the MIPS program. .eqv print_int 1 .eqv print_string 4 .eqv read_int 5 .eqv exit 10 .eqv read_char 12

Find all the obvious bugs and correct the MIPS program.

Find all the obvious bugs and correct the MIPS program. .eqv print_int

.eqv print_int 1

.eqv print_string 4

.eqv read_int 5

.eqv exit 10

.eqv read_char 12

### Binary search #############################################################

.text

binsearch:

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

# $a0 - number n

# $a1 - Lower limit lo

# $a2 - Upper limit hi

# $v0 - Position of n in list if found, -1 if not found

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

addi $sp, $sp, -4

sw $ra, 0($sp)

bge $a1, $a2, binsearch_not_found

sub $t0, $a2, $a1

srl $t0, $t0, 2

add $t1, $a1, $t0

sll $t2, $t1, 2

lw $t3, list($t2)

beq $t3, $a0, binsearch_found

blt $t3, $a0, binsearch_upper_half

binsearch_lower_half:

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

subi $a2, $a2, 1

jal binsearch

j binsearch_return

binsearch_upper_half:

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

addi $a1, $t1, 1

jal binsearch

j binsearch_return

binsearch_found:

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

move $v0, $t2

j binsearch_return

binsearch_not_found:

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

li $v0, -1

binsearch_return:

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

addi $sp, $sp, 4

lw $ra, 0($sp)

jr $ra

### Main #####################################################################

.globl main

main:

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

li $v0, print_string

la $a0, input

syscall

li $v0, read_int

syscall

move $a0, $v0

move $a1, $zero

lw $a2, length

subi $a2, $a2, 1

jal binsearch

li $t0, -1

beq $v0, $t0, not_found

found:

######

mul $t0, $v0, 4

lw $a0, list($t0)

li $v0, print_int

syscall

li $v0, print_string

la $a0, success

syscall

j repeat

not_found:

##########

li $v0, print_string

la $a0, failure

syscall

repeat:

#######

li $v0, print_string

la $a0, continue

syscall

# Read sign

li $v0, read_char

syscall

move $t0, $v0

li $v0, print_string

la $a0, newline

syscall

# end with 'j'

bne $t0, 'j', main

li $v0, exit

syscall

### data ####################################################################

.data

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

input: .asciiz "Which number? "

continue: .asciiz "Abort? (j) "

failure: .asciiz "not found "

success: .asciiz " found "

newline: .asciiz " "

length: .word 100

list: .word 1, 4, 9, 16, 25, 36, 49, 64, 81, 100,

.word 121, 144, 169, 196, 225, 256, 289, 324, 361, 400,

.word 441, 484, 529, 576, 625, 676, 729, 784, 841, 900,

.word 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600,

.word 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500,

.word 2601, 2704, 2809, 2916, 3025, 3136, 3249, 3364, 3481, 3600,

.word 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900,

.word 5041, 5184, 5329, 5476, 5625, 5776, 5929, 6084, 6241, 6400,

.word 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100,

.word 8281, 8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000

MIPS assembler program for the binary search [1] of numbers in a sorted field list. The binsearch function is based on the following pseudocode: int binsearch(int n, int lo, int hi) { if (hi

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!