Mips-адрес вне диапазона Исключение времени выполнения - PullRequest
0 голосов
/ 28 мая 2020

Я пытался получить ответ из сообщения 2D-массив в MIPS , который предоставляет полное кодированное решение для основной матрицы строк в качестве ввода пользователя.

    .data
read_row_matrix_prompt_p:   .asciiz "Enter an integer: "
###########################################################

.text
read_row_matrix:
        li $t3, 0               # initialize outer-loop counter to 0
    li $t2, 3
    li $t1, 3
read_row_matrix_loop_outer:
        bge $t3, $t1, read_row_matrix_loop_outer_end
        li $t4, 0               # initialize inner-loop counter to 0

read_row_matrix_loop_inner:
        bge $t4, $t2, read_row_matrix_loop_inner_end
        mul $t5, $t3, $t2       # $t5 <-- width * i
        add $t5, $t5, $t4       # $t5 <-- width * i + j
    sll $t5, $t5, 2         # $t5 <-- 2^2 * (width * i + j)
        add $t5, $t0, $t5       # $t5 <-- base address + (2^2 * (width * i + j))

        li $v0, 4               # prompt for number
        la $a0, read_row_matrix_prompt_p
        syscall

        li $v0, 5               # read a integer number
        syscall

        sw $v0, 0($t5)          # store input number into array <--- ""Error""
        addiu $t4, $t4, 1       # increment inner-loop counter
        b read_row_matrix_loop_inner    # branch unconditionally back to beginning of the inner loop

read_row_matrix_loop_inner_end:
        addiu $t3, $t3, 1       # increment outer-loop counter
        b read_row_matrix_loop_outer    # branch unconditionally back to beginning of the outer loop

read_row_matrix_loop_outer_end:

, и я столкнулся с следующая ошибка:

 line 28: Runtime exception at 0x00400048: address out of range 0x00000000

Подобная ошибка была опубликована во многих вопросах, но каждый сценарий кажется локальным.

Я понимаю, что # t5 на самом деле будет начинаться с $ t0 для начала, поскольку все инициализации делают его нулевым. Я попытался начать с 1 и для счетчиков, но все равно столкнулся с той же ошибкой.

В чем может быть проблема?

1 Ответ

1 голос
/ 28 мая 2020

Добавление этой части кода перед выполнением процедуры помогло мне инициализировать массив, и он работал нормально

    mul $a0, $t1, $t2 #multiply to get the 2d array size and store in a0 register
    sll $a0, $a0, 2 #multiply the resulting output with 2^2 = 4 for integers address size location

    li  $v0, 9 #allocate address with memory size as in a0
    syscall
    move $t0,$v0 #resulting memory stored in t0 register    
...