【发布时间】:2016-01-30 09:38:37
【问题描述】:
所以我必须在 MIPS 中为我的大学写一个代码,它将 A[i][j] 与 B[i][j](A 和 B 是 4x4 数组)进行比较,并将放置最大的A[i][j] 中的数字和 B[i][j] 中的最小数字。这是我已经写的代码:
.data
Ann: .word 4, 6, 10, 5, 4, 7, 10, 8, 3, 6 ,7, 12, 3, 2, 15, 6
Ban: .word 3, 7, 5, 6, 5, 12, 18, 9, 7, 6, 12, 4, 2, 7, 8, 4
.text
.globl main
main: la $t0, Ann # $t0 represents start address of A[i][j]
la $t1, Ban # $t1 represents start address of B[i][j]
lw $s2,0($t0)
lw $s1,0($t1)
addi $s5, $zero, 4 # set maximum iteration to be 4
addi $s6, $zero, 0 # set i = 0
loopi: addi $s7, $zero, 0 # set j = 0
jal loopj # starts inner loopj
addi $s6, $s6, 1 # i++
bne $s5, $s6, loopi # continue loopi if i < 4
j finish
loopj: sll $t7, $s6, 2
add $t7, $t7, $s7
sll $t7, $t7, 2 # 4 * ((i * 4) + j)
add $t9, $t7, $s2 # address of A[i][j]
lw $t6, 0($t9) # value of A[i][j]
add $t4, $t7, $s1 # address of B[i][j]
lw $t5, 0($t4) # value of B[i][j]
slt $t8,$t6,$t5
beqz $t8,cont
add $t2,$zero,$t6
add $t6,$zero,$t5
add $t5,$zero,$t2
sw $t6,0($t4)
sw $t5,0($t9)
cont: addi $s7, $s7, 1 # j++
bne $s5, $s7, loopj # continue loopj if j < 4
jr $ra
finish: li $v0, 1
add $a0,$s5, $zero
syscall
当我尝试将它运行到 spim 缓存时,我在指令“lw $t6, 0($t9) # value of A[i][j]”处遇到异常 .... 可能是什么问题,我不知道:\
【问题讨论】: