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).
发布评论
评论(1)
他们要求您将
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 fromn
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).