MIPS:如何加载数组最后一个元素的字节偏移

发布于 2025-02-04 20:41:06 字数 285 浏览 2 评论 0原文

我怎么样?

enter image description here

enter image description here

do I load ((n-1) + 4)*4 as the byte offset?

how would I?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水波映月 2025-02-11 20:41:06

他们要求您将n从索引转换为字节偏移。 由于这些是基于零的数组,因此长度为n,如果在数组中作为索引,则(根据基于零的索引的定义)超过数组的末尾,因此字节偏移从n转换为数组末端的4个。

您可以将n从索引转换为字节偏移吗? 那就是那里所需要的。


MIPS只有一个地址模式,即基本+位移。 该地址模式可以为指针添加一个常数以形成有效的地址,并且该常数应被视为字节偏移,因为没有机会在地址模式内移动或乘以。

如果您的指针超过末端为1个索引位置,则必须是末端的4个字节。 如果数组至少具有一个元素,则使用位移为-4的base+位移,然后引用实际的最后一个元素(因为i据说在数组的范围内)。

They are asking you to convert n from an index to a byte offset.  Since these are zero-based arrays, the length, n, if taken as an index in the array, is (by definition of zero-based indexing) past the end of the array by 1, so the byte offset converted from n will be 4 past the end of the array.

Can you convert n from an index to a byte offset?  That is all that's needed there.


MIPS has only one addressing mode, which is base+displacement.  That addressing mode can add a constant to a pointer to form the effective address — and this constant should be thought of as a byte offset, since there is no opportunity to shift or multiply within the addressing mode.

If you have a pointer that is 1 index position past the end, then must also be 4 bytes past the end.  Using base+displacement where the displacement is -4 then refers to the actual last element, assuming the array has at least one element (it does because i is said to be within the bounds of the array).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文