背景
私は現在、宿題のために小さな MIPS プログラムに取り組んでおり、その過程でいくつかの言語を学んでいます。私はこれに非常に慣れていないため、実行している操作の最も基本的な側面でさえ、自分自身に自信がありません。さらに、私のインストラクターは、私たちの課題で疑似コードを使用しないことを主張しています。
割り当て
私の割り当ての質問は次のとおりです。最初の 20 個のビギー数を繰り返し (ループで) 計算し、MIPS メモリ内のベース アドレスが register に格納されてB(i) = 2i + 17i
いる配列にそれらを順次格納するとします。を計算する MIPS コード (完全にコメント付き) を記述してください。B
$s0
B(i), 1 < i < 20
私の解決策
私が現在持っているもの:
.globl main
main:
.data
BiggieArray:
.space 80 #4 bytes per word * 20 biggie numbers = 80 bytes reserved
.text
addi $s1, $zero, 1 #$s1 tracks i, initialize i with value of 1
addi $s2, $zero, 21 #$s2 holds 21, for use in comparing with the value of i
addi $s3, $zero, 2 #$s3 holds the value for the first mult
addi $s4, $zero, 17 #$s4 holds the value for the second mult
STARTLOOP:
beq $s1, $s2, ENDLOOP #compares i ($s1) with $s2. If they are equal, i > 20, so branch to the end of the loop.
add $t0, $s1, $s1 #find 2i
add $t0, $t0, $t0 #find 4i, use as offset for BiggieArray
addi $t0, $t0, -4 #adjusts to start from index 0 instead of index 1
mult $s1, $s3 #Calculates 2i
mflo $s5 #$s5 holds 2i
mult $s1, $s4 #Calculates 17i
mflo $s6 #$s6 holds 17i
add $s7, $s5, $s6 #$s7 holds 2i+17i
add $t1, $s0, $t0 #$t1 holds the current address of BiggieArray[i]
sw $t1, 0($s7) #stores the value 2i+17i into RAM ?????
addi $s1, $s1, 1 #increment i
j STARTLOOP
ENDLOOP:
私の質問
$s0
現在、何も初期化していないことに気付きましたが、それが問題の原因ではありません。私が混乱しているのは、その値を に2i+17i
戻す方法ですBiggieArray
。sw がどのように機能するかについてのヘルプまたは非常に簡単な説明をいただければ幸いです。