この c コードを MIPS に変換し、SPIM で実行しようとしています。
int A[100], B[100];
for(i=1; i<100; 1++){
A[i] = A[i-1] + B[i];
}
これまでのところ、これは私が持っているものです。
# comments are delimted by has marks
.data
A: .word 0:100 # array of 12 integers
B: .word 0:100 # array of 12 integers
.text
main:
li $v0, 1 # load the value "1" into register $v0
li $t0, 1 # load the value "1" into register $t0
li $t1, 100 # load the value "100" into register $t1
blt $t0, $t1, loop # branches to Loop if $t0 < 100
la $t9, B
la $t8, A
loop:
sll $t0, $t0, 2
add $t2, $t9, $t0
lw $s4, 0($t9)
add $t3, $t0, -1
add $t4, $t8, $t3
lw $s5, 0($t4)
add $t5, $t2, $s5
add $t6, $s0, $t0
sw $t7, 0($t5)
addi $t0, $t0, 1
li $v0, 1 # system call for print_int
move $a0, $t0 # the sum to print
syscall # print the sum
SPIM で実行すると、次のエラーが発生します。
PC=0x00400040で例外発生 データ/スタック読み取りの不正なアドレス: 0x00000004 PC=0x0040004cで例外発生 inst/data fetch でアラインされていないアドレス: 0x00000003 PC=0x00400058 で例外が発生しました データ/スタック読み取りの不正なアドレス: 0x00000000 0x0040006cで非命令実行を試みる
何らかの方向性がいいでしょう。ありがとう