質問
私は、MIPSアセンブリを傾くし始めています、と私はシンプルなwhile
ループを記述しようとしています。これは、Cコードにequivilentされます:
int A[5];
for(i=0;i<5;i++) A[i]=i;
だから、私はbeq
ループを作るためにwhile
を使用することができます知っているが、私は、メモリ・アドレスの次のレジスタに移動するたびにインクリメントする方法がわかりません。私は多分slt
オペランドが有用である可能性があると思いますが、私は知りません。
解決
に$ 3ポイントを仮定
lis $4
.word 4
lis $5
.word 1
add $7, $4, $5 ;$7 = 5
add $6, $0, $0 ;$6 = 0
loop:
sw $6, 0($3)
add $3, $4, $3 ;point to next "int"
add $6, $5, $6 ;add 1 to our counter
bne $7, $6, loop ;we will stop at 5
他のヒント
.data
A: .space 20 #declared 20 bytes of storage to hold array of 5 int
__start:
lw $t0, A #load base address of array
li $t1, 0
loop: sw $t1($t0), $t1
addi $t1, $t1, 4
ble $t1, 20, loop
#continue code or simple exit after this
所属していません StackOverflow