1

I'm trying to write a mips function which return the position of the maximum value but I'm getting this exeption (Error in /home/ams/Bureau/part2a line 21: Runtime exception at 0x00400028: address out of range 0x00000000)

# MIPS assembly code

# $s0 = array base address, $s1 = i
# initialization code

main: lui  $s0, 0x23B8           # $s0 = 0x23B80000
     ori  $s0, $s0, 0xF000   # $s0 = 0x23B8F000
     addi $s1, $0, 0            # i = 0
     addi $t2, $0, 1000      # $t2 = 1000
     addi $t3, $0, 0            # $t3 =   max
     addi $s4, $0 , 0           #  $s4 = max indice

max:
loop: slt  $t0, $s1, $t2      # i < 1000?
     beq  $t0, $0, done      # if not then done
     sll $t0, $s1, 2              # $t0 = i * 4 
     add  $t0, $t0, $s0      # address of array[i]
     
     
     lw   $t1, 0($t0)        # $t1 = array[i] ERROR HERE 
     slt $t5, $t3, $t1      # max < array[i]
     beq $t5, $0,else   # if not then ense
     addi $t3,$t1, 0    # $t3 =: array[i]
     addi $s4, $s1,0    # $s4 =: i 
     #end
     
     else:   
     addi $s1, $s1, 1        # i = i + 1
     j    loop               # repeat

done: 
    addi  $v0, $s4, 0        # retval = max
    jr    $ra                # Return

any suggestion please?

1 Answer 1

1

You are setting $s1 to 0, and then trying to dereference it. Perhaps you meant $t0?

lw   $t1, 0($t0)
Sign up to request clarification or add additional context in comments.

4 Comments

still having the same exeption but know Error in /home/ams/Bureau/part2a line 20: Runtime exception at 0x00400028: address out of range 0x23b8f000
Then your initialization is wrong, as it's the exact address you load $s0 with.
yes you are right something wrong with the initialization but i can't figure out what :/ any guess ?
How can you hope to find the maximum of an array if you don't know where it is?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.