转换C到MIPS - 嵌套数组 [英] Convert C to MIPS - Nested Arrays

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

问题描述

我学习MIPS汇编语言在书中跨越这个例子中来,对我来说,似乎不正确。如果它不会是第一个错误,我在这本书中找到。

I am studying the MIPS assembly language and came across this example in the book and to me it seems incorrect. If it is it wouldn't be the first mistake I found in this book.

变量˚F先按g 分配寄存器 $ S0 $ S1 分别为数组的基地址 A B $ S6 $ S7 分别。

The variables f and g are assigned registers $s0 and $s1 respectively, the base addresses for the arrays A and B are $s6 and $s7 respectively.

的C code的例子是:

The c code example is:

f = g - A[B[4]];

和提供相应的MIPS汇编是:

And the corresponding MIPS assembly provided is:

lw  $t0, 16($s7)
lw  $s0, 0($t0)
sub $s0, $s1, $s0

从我的理解上面的MIPS code会从内存由 $ T0 ,然后从 $ S1 ,而不是访问索引 $ T0 $ S6 >

From my understanding the above MIPS code would load some random data from memory at the address provided by $t0 and then subtract it from $s1 and not access the index $t0 of the array denoted in $s6.

这是我的理解正确的MIPS汇编将沿着线:

The correct MIPS assembly from my understanding would be along the lines of:

lw  $t0, 4($s7)
add $t0, $t0, $s6
sll $t0, $t0, 2
lw  $s0, 0($t0)
sub $s0, $s1, $s0

我是正确的,这是书中的错误还是我误解的东西。

I am correct that this is an error in the book or am I misunderstanding something.

编辑:在纠正MIPS修正错误美元,由多德指出,C $ç

Fixed an error in the corrected mips code as pointed out by Chris Dodd

推荐答案

正如书中指出我的许多有错误。自从发现这个错误我发现了几个这样的错误。

As pointed out my many there was an error in the book. Since discovering this error I found several such errors.

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

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