0
votes

Why I have this error:

ine 101: Runtime exception at 0x00400138: fetch address not aligned on word boundary 0x10010005

Here's the code:

    .data
     array: .word 3.1, 3.2, 20.0
     .text
     la   $s1, array
     li $t0, 0
       li $s5, 1
li $t1,0
          sortloop: slti $s0, $t0, 3           #Checking if the counter is less than 20
                    beq  $s0, $zero, exitout       #if it's greater or equal to 20 exit the loop
                    sll  $t4, $t0, 2             # i*4
                    add  $t4, $t4, $s1           # adding the base register to $t4
                    l.s  $f11, 0($t4)            # loading from memory the element of the array that holds a float value
                    add  $s5, $s5, $t0
          innloop:  slti $s0, $s5, 3           #Checking if the counter is less than 20
                    beq  $s0, $zero, exitinn       #if it's greater or equal to 20 exit the loop
                    sll  $t1, $s5, 2             # i*4
                    add  $t1, $t1, $s1           # adding the base register to $t7
                    l.s  $f19, 0($t1)            //this is line 101
                    c.le.s $f19, $f11
                    bc1f, addcounter
                    add.s $f20, $f14, $f19       
                    l.s  $f11, 0($t1)
                    l.s  $f20, 0($t4)
                    add  $s1, $s1,1
         j innloop
                   addcounter:
                   add  $s1, $s1,1
                   j innloop
                   exitinn:
                   add $t0, $t0,1
                   j sortloop
exitout:
1
add $s1, $s1,1 looks suspicous. - Michael

1 Answers

1
votes

On MIPS you cannot load floats from unaligned addresses, so you get an error when you try to do that.

You are reading a floating point number into $f19. You correctly multiply i by 4, but in the inner loop you only add one to $s1 on every loop and don't multiply it anywhere. You have to add 4 to get to the next float in the array to get the correct values.