私は現在、コンピュータ アーキテクチャのコースを受講しており、基本的な R タイプおよび I タイプの命令 (これもRISCアーキテクチャです) などについて学習しています。これを最適化する方法がわかりません。コード。
説明: このコードは、ゼロに到達するまで、数字の配列 ($s1 が指す) に単語を追加します。結果は $t1 に格納されます。$t0 は現在の単語を保持します。
add $t1, $zero, $zero # Initialize result to zero
again:
lw $t0, 0($s1) # Load the word from the array
beq $t0, $zero, done # Terminate if current word is a zero
add $t1, $t1, $t0 # Add current word to result
addi $s1, $s1, 4 # Point to the next word in the array
beq $t1, $t1, again # Loop again
done:
nop # Do nothing
コードの最適化に苦労しています。(常に true であるため) は不要だと思いbeq $t1, $t1, again
ますが、削除する方法がわかりません。これが私の試みですが、コードが終了しないことに気付きました。
add $t1, $zero, $zero # Initialize result to zero
again:
lw $t0, 0($s1) # Load the word from the array
add $t1, $t1, $t0 # Add current word to result
addi $s1, $s1, 4 # Point to the next word in the array
bne $t1, $zero, again # If result is not zero, loop
done:
nop # Do nothing
終了ゼロをチェックして完了にジャンプすることは決してありません。しかし、別のチェックを追加すると、コードは以前と同じになるのではないでしょうか?