2017-06-03 21 views
0

配列に最大値を見つけるプログラムを書いてみたい。 私のプログラムを起動しようとすると、「PCで例外が発生しました= 0x0040004c」というエラーが表示されます。私はこれが何を意味するのか分かりませんし、自分のコードに何が間違っているのか分かりません。 la $a1, 28($a0) 間違っている:プログラムの残りの部分をスキップMIPSエラー - 配列内で最大値を見つける

.data 
liste: .word 1, 2 ,3 ,41, 5, 6, 7 

.text 
main: 
    la $a0 liste  #adresse des ersten Elements in $a0 gespeichert 
    la $a1 28($a0)  #adresse des letzten Elements in $a1 gespeichert 
    li $v0 0   #speichere 0 in v0 

tester: 
    beq $a0 $a1 exit #test, if we are at the end of the array 
    j findmax 

findmax: 
    la $t0 ($a0)  #copy a0 in t0 
speichermax: 
    la $v0 ($t0)  #adress of t0 (Maximum) in v0 
    lw $v1 ($v0)  #value of the max in v1 

loop: 
    la $t0 4($t0)  #go to the next field content 
    beq $v0 $a1 exit #end of field is reached 
    lw $t1 ($t0) 

    sub $t1 $t1 $v1   # t1 = t1 - v1 
    bgtz $t1 speichermax   
    #bgt $t1 $v1 speichermax #test if t1>v1 -> yes: save the new max in v1 (über speichermax) 
    j loop 

exit: 
    lw $a0 ($t0) #print the maximum 
    li $v0 1 
    syscall 

    li $v0 10 #exit 
    syscall 
+0

アドレス0x0040004cの命令で例外が発生しました。シミュレータでは、そのアドレスが対応する命令を簡単に見ることができます。だから、その命令がなぜ例外を引き起こしているのかを理解する必要があります。無効なメモリアドレスにアクセスしようとしている可能性があります。コードを見るだけでその理由を理解できない場合は、シミュレータのシングルステップ機能を使用してコード命令を命令ごとに実行し、関連するすべてのレジスタとメモリ位置の値を確認してください。 – Michael

答えて

0

私は、これがあると信じています。試してみてください:addi $s1, $a0, 28

関連する問題