Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
854 views
in Technique[技术] by (71.8m points)

array on mips from C to MIPS?

B[8] = A[i–j];

how do you use the arrays while trying to convert into MIPS the above C expression? i thought something like :

lw $t0, 16 ($s7)
sub $t1, $s3, $s4
lw $t2, $t1 ($s6)

considering that

$s6 holds A
$s7 --- B
$s3 ---- i
and $s4 -- j

but am not sure about how to do the calculationg to actually get on A [i-j]

any suggestion?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Well, first off, 16($s7) is wrong. Assuming that B and A are arrays of 32-bit integers, the offset is 8 * 4 = 32.

Next, simply add $t1 and $s6 and load from there.

lw  $t0 32($s7)
sub $t1 $s3 $s4
add $t1 $s6 $t1
lw  $t2 0($t1)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...