我正在尝试来自MIPS 中的 post 2D Array 的答案,它为 Row 主矩阵作为用户输入提供了完整的编码解决方案。
.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开始,但仍然面临同样的错误。
这里可能是什么问题?