array on mips from C to MIPS?

大兔子大兔子 提交于 2021-01-29 07:57:04

问题


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?


回答1:


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)


来源:https://stackoverflow.com/questions/21227087/array-on-mips-from-c-to-mips

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!