从 C 到 MIPS 的 mips 上的数组? [英] array on mips from C to MIPS?

查看:117
本文介绍了从 C 到 MIPS 的 mips 上的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

在尝试将上述 C 表达式转换为 MIPS 时如何使用数组?我想的是这样的:

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)

考虑到

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

但我不确定如何进行计算以实际获得 A [i-j]

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

有什么建议吗?

推荐答案

好吧,首先,16($s7) 是错误的.假设 B 和 A 是 32 位整数数组,偏移量为 8 * 4 = 32.

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

接下来,只需添加 $t1$s6 并从那里加载.

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)

这篇关于从 C 到 MIPS 的 mips 上的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆