2
안녕하세요 여러분, 모든 i와 j에 대해 C [i] [j] = A [i] [j] + B [j] [i] 2D 배열의 16입니다.MIPS의 2D 배열을 통해 이동
이것은 내 코드의 주요 부분입니다 (아래 참조).
SPIM에서이 코드를 실행하면 데이터/스택 읽기시 잘못된 주소 인
을 나타내는 "lw $ t4, 0 ($ t4) # 값 B [j] [i]"예외가 발생했습니다.각 레지스터에 저장된 값을 검사하면 i == 0x1임을 알게되었지만 j는 0xbf0에 도달했습니다! (That 's 3056)
내 j가 0에서 15로만 증가하기로되어 있기 때문에 왜 이런 일이 일어 났는지 전혀 알지 못합니다. 도와주세요!
la $t0, A # $t0 represents start address of A[i][j]
la $t1, B # $t1 represents start address of B[i][j]
la $t2, C # $t2 represents start address of C[i][j] displacement of A will be the same as C
addi $t3, $zero, 16 # set maximum iteration to be 16
addi $t5, $zero, 0 # set i = 0
addi $t6, $zero, 0 # set j = 0
loopi:
jal loopj # starts inner loopj
addi $t5, $t5, 1 # i++
bne $t3, $t5, loopi # continue loopi if i < 16
j finish
loopj:
sll $t7, $t5, 4
add $t7, $t7, $t6
sll $t7, $t7, 2 # 4 * ((i * 16) + j)
add $t9, $t7, $t0 # address of A[i][j]
lw $t9, 0($t9) # value of A[i][j]
sll $t4, $t6, 4
add $t4, $t4, $t5
sll $t4, $t4, 2 # 4 * ((j * 16) + i)
add $t4, $t4, $t1 # address of B[j][i]
lw $t4, 0($t4) # value of B[j][i]
add $t4, $t4, $t9 # A[i][j] + B[j][i]
add $t7, $t7, $t2 # address of C[i][j]
sw $t4, 0($t7) # store answer into C[i][j]
addi $t6, $t6, 1 # j++
bne $t3, $t6, loopj # continue loopj if j < 16
jr $ra
finish:
오 감사합니다, 나는 그것을 간과! 내 문제가 해결되었습니다. 당신은 큰 도움이됩니다. – user1802890