开发者

MIPS memory restrictions?

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?


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 - so lw $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 using la, but one can generally produce more optimal code by using la 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 using la 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:

array:  .word 0:20000
~
la     $s0, array          # get address of array
la     $s1, 40000          # get offset into a register
add    $s0, $s0, $s1       # add offset to address, i.e. calculate (array+40000)
lw     $s1, 0($s0)         # fetch data from (array+40000)
lw     $s2, 10000($s0)     # fetch data from (array+40000+10000)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜