简体   繁体   English

将MIPS32转换为C:将数组的基地址添加到任意值及其含义

[英]Convert MIPS32 to C: adding an array's base address to arbitrary value and its meaning

I'm working on a homework assignment right now, and I'm given this information: 我现在正在从事一项家庭作业,并且获得了以下信息:

$s6 is the location of the base address of array A , $s0 is the location of the value of f (not specified). $ s6是数组A的基地址的位置, $ s0f值(未指定)的位置。

It wants me to convert some instructions to a C statement. 它希望我将一些指令转换为C语句。 Here is my question though, because if this is answered I can very easily do the rest of this problem: 不过,这是我的问题,因为如果得到回答,我可以很容易地解决此问题的其余部分:

add $t0, $s6, $s0 加$ t0,$ s6,$ s0

Is that saying $t0 = (the base address of array A) + f or is it saying $t0 = A[0+f] ? 是说$t0 = (the base address of array A) + f还是说$t0 = A[0+f]

Because if the base address of A were 0x04000000 and I used addi to add 4 to that base address, yielding 0x04000004, and assigning that value to t0, what I'm saying is that t0 = A[1] (assuming I'm storing integers). 因为如果A的基址为0x04000000,并且我使用addi将4加到该基址上,产生0x04000004,并将该值分配给t0,那么我的意思是t0 = A [1](假设我正在存储整数)。

But since I don't know the value of f, I'm unsure of how to represent this in C, because I know I'm modifying the index, but I don't know by how much. 但是因为我不知道f的值,所以我不确定如何用C表示它,因为我知道我正在修改索引,但是我不知道要多少。 Would it be more accurate to say (given the instruction above): (根据上述说明)说的更准确吗:

$t0 = A[f/4]

I'm new to all of this ha. 我是这一切的新手。 Hopefully I demonstrated that I've done a bit of research trying to figure this out. 希望我证明我已经做了一些研究以弄清楚这一点。

Thanks 谢谢

OSFTW OSFTW

There is no dereferencing in this instruction: 该指令中没有取消引用:

add $t0, $s6, $s0

It's like saying 就像在说

t0 = s6 + s0;

In a C-like pseudocode. 在类似C的伪代码中。 Or for your example: 或举个例子:

t0 = (char *)A + f;

To get a value out of A, it would look something like: 为了从A中获得一个值,它看起来像这样:

lw $t1, 0($t0)

After having done the previous add instruction so that $t0 points to the right place in the array. 完成上一条add指令后, $t0指向数组中的正确位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM