MIPS Assembly programming

Hi there,
I need to implement in assembly mips an iterative binary search method.
Here's my code:
# this program implements binary search

# the equivalent pseudo code is the following:

# first = 0
# last = size -1
# while (last - first > 1) {
# mid = (last-first)/2 + first
# if A[mid] == val
# break;
# if A[mid] > val
# last = mid;
# continue
# else
# first = mid;
# continue;
# }


.data 0x10000000

size: .word 0x0000000a # array size

.data 0x10000004

search: .word 0x0000000d # search term

.data 0x10000008

result: .word 0xffffffff # result = -1

.data 0x10000100

array: .word 0x00000001 # the array
.word 0x00000005
.word 0x00000007
.word 0x00000009
.word 0x0000000b
.word 0x0000000d
.word 0x00000010
.word 0x00004000
.word 0x00050000
.word 0x00700000

.text 0x0400000

sw $t0, 0 # $t0 = 0, that's our "first" pointer
sw $t1, size # $t1 - size
addi $t1, $t1, -1 # $t1 = size - 1, our "last" pointer
j condition # goto condition

sub $t2, $t1, $t0 # $t2 = last - first
bgt $t2, 1, while # if ($t2 > 1) goto while
j exit # if not, goto exit

div $t3, $t2, 2 # $t3 = (last - first) / 2
add $t3, $t3, $t0 # $t3 = t3 + first
lw $t5, array($t3) # $t5 = array($t3)
lw $t6, result # $t6 = result
beq $t6, $t5, found # if value found, goto found
bgt $t5, $t6, isGreater # if array[$t3] > result, goto isGreater
addi $t0, $t3, 0 # else, first = mid
j condition # check the condition and start over the loop

sw $t3, result # result = $t3
j exit # goto exit

addi $t1, $t3, 0 # else, last = mid
j condition # check the condition and start over the loop

exit: sw $t4, 4($t6) # result = $t4
j end # jump to end

end: j end # internal loop to end the program

however when I try to run it I get errors of bad data.
Any ideas?

  1. 👍
  2. 👎
  3. 👁

Respond to this Question

First Name

Your Response

Similar Questions

  1. Help!

    How are Boolean search strategies and other search filters useful? A.They organize results alphabetically. B.They narrow the search results. C.They increase the number of search results. D.They find creative sources. Please help

  2. History

    Which of the following were the three main parts of Athenian democratic government? A. the Congress, the Council, and the Assembly B. the House of Representatives, the President, and the Assembly C. the Assembly, the Courts, and

  3. accounting

    Cargin Company uses the FIFO method in its process costing system. The Assembly Department started the month with 15,000 units in its beginning work in process inventory that were 50% complete with respect to conversion costs. An

  4. Biostatistic

    An enzymatic method for determining alcohol in wine is evaluated by comparison with a gas-chromatography (GC) method. the same sample is analyzed several times by both methods with the following results (% ethanol). Enzymatic

  1. Math

    1: An employer provides two payment options for employees. Option A: Receive $200 the first week. Receive an additional $50 for each of the following weeks. Option B: Receive $200 the first week. Receive an additional 10% for each

  2. chem

    name the following compounds and tell what type of compound they are (binary ionic. ternary ionic, or binary molecular) a)FeBr3 b)CBr4 c)Na2Cr2O7


    provide a situation when scientific method, case study method, survey method, Naturalistic observation method, Correlation method, and Experimental method could be applied

  4. math

    Find the binary equivalent of x^8+x^3+x+1 x^1000 + x^11 + x + 1 I just converted the decimal-format exponents to binary format (0's and 1's times powers of 2). The reason you did not get a reply so far is that most of the tutors

  1. Science

    Why is binary fission in Paramecium considered as asexual reproduction? A) Binary fission produces identical daughter cells. B) Binary fission produces non-identical daughter cells. C) Binary fission produces more than two

  2. chemistry

    name the following compounds and tell what type of compound they are (binary ionic, ternary ionic or binary molecular) FeBr3, b) CBr4 and c) Na2Cr2O7

  3. Math

    The assembly of a machine takes 3/4 hour. There are twelve steps in the assembly process. What is the average time for each step? 3/4 /12= 4/3 x12/1 =16 is this right

  4. chemistry

    I have 3 questions that I am uncertain about. 1) what determines the order in which the coumponent elements of binary molecular compounds are written? 2) Name the Binary compound according to the prefix system for As2O5 3) write

You can view more similar questions or ask a new question.