0
votes

I'm writing a small program in assembly (MIPS) where I have to read 11 floats and store them in an array:

    .include "../../ac1_macros.h"
    .eqv size, 11
    .data
array:  .float 0:size
str1:   .asciiz "Insert 11 numbers: "

    .text
    .globl main
main:   la $t0, array   
    print_str(str1)
    li $t1, 1
fill_array:
    sll $t0, $t0, 2
    read_float()
    s.s $f0, ($t0)
    addi $t1, $t1, 1
    bne $t1, 11, fill_array
    jr $ra

I get the following exception when inserting the first number.

Runtime exception at 0x0040004c: address out of range 0x40040000

What am I doing wrong? Has it something to do with the directive align that I am not using? Thanks in advance.

1
BTW, "read_float" and "print_str" are just macros. They have worked before, so I don't think that's the problem. - JPC

1 Answers

0
votes

You shift $t0 and don't return it, so it will become bigger and bigger.

Not tested, try this.

    .include "../../ac1_macros.h"
    .eqv size, 11
    .data
array:  .float 0:size
str1:   .asciiz "Insert 11 numbers: "

    .text
    .globl main
main:   la $t0, array
    print_str(str1)
    li $t1, 1
fill_array:
    read_float()
    s.s $f0, ($t0)
    addi $t1, $t1, 1
    addi $t0, $t0, 4 # proceed to the next element
    bne $t1, 11, fill_array
    jr $ra