MIPS内存限制?
我想问一下关于内存访问的问题。当我执行 load word
命令时,存在哪些内存限制?这意味着我可以用作偏移量或基址寄存器的最大数字是多少?
寄存器是 32 位,据我所知,“立即数”是 16 位。 因此,我很确定我不能做这样的事情
array: .word 0:20000
~
la $s0, array
lw $s1, 15000($s0)
...
,所以如果我想访问 15000,我可能需要la
一些更小的东西,然后从那里继续,对吗? 但是我需要访问的较小值是多少才能正常,为什么?
I would like to ask about memory accessing. When I execute a load word
command, what memory restrictions exist? Meaning what's the biggest number I can use as offset or base register?
Registers are 32 bits and as far as I know the "immediate" is 16 bits.
Thus, I'm pretty sure I can't do something like
array: .word 0:20000
~
la $s0, array
lw $s1, 15000($s0)
...
So if I want to access the 15000, I might need to la
something smaller and go on from there right?
But what's the smaller value I need to access in order to be ok and why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
lw
中的立即数字段是16位,是的;并且它是有符号的二进制补码,因此立即偏移量的可能范围是 -32768..32767 - 所以lw $s1, 15000($s0)
应该没问题。请注意
la
并不是真正的 MIPS 指令。相反,它指示汇编器生成最佳指令序列,以便将您指定的立即值放置在指定的寄存器中。因此,可以使用la
设置完整的 32 位范围的值,但是通常可以通过使用la
一次将合适的值放入某个寄存器中来生成更优化的代码,例如多个后续指令能够使用该值的立即偏移量,而不是每次需要立即值时使用la
。因此,假设您需要从数组的偏移量 40000 和 50000 加载值,您可以这样做:
The immediate field in
lw
is 16 bits, yes; and it is signed two's complement, so the possible range of immediate offsets is -32768..32767 - solw $s1, 15000($s0)
should be fine.Realise that
la
is not a real MIPS instruction. Rather, it directs the assembler to generate the most optimal instruction sequence such that the immediate value you have specified is placed in the specified register. Thus, the full 32 bit range of values may be set usingla
, but one can generally produce more optimal code by usingla
once to place a suitable value into some register such that several subsequent instructions are able to use immediate offsets from that value than by usingla
each time an immediate value is needed.So, supposing you needed to load values from offsets 40000 and 50000 of your array, you might do: