3
votes

My textbook says that the MIPS assembler must break large constants into pieces and then reassemble them into a register. And that it uses the $at as a temporary register for

I've been looking for a concrete example of this, does anyone have one?

I've seen some websites say that the la pseudo-instruction converts into instructions using $at, but that doesn't seem to be needed. For example:

la $t0, 0xABCD1234

converts into

lui $t0, 0xABCD
ori $t0, $t0, 0x1234
1
Try reading this: cs.umd.edu/class/sum2003/cmsc311/Notes/Mips/load32.html ... it's been about 15 years since I've used MIPS - Tim Biegeleisen
You don't need $at to assemble 32-bit constants in general. You may need it to do branches when the native beq/bgez/bgtz/blez/bltz aren't enough and you need to slt* to build a different predicate. - EOF
@TimBiegeleisen the link is no longer working, sadly. - Zap

1 Answers

3
votes

Here's an example taken from my answer to an earlier question regarding the use of li and lw:

Given the following code:

.data
ten: .word 10

.text 
main:
    lw $t0, ten

SPIM would generate the following instruction sequence for the lw:

0x3c011001  lui $1, 4097                    ; lw $t0,ten
0x8c280000  lw $8, 0($1)

The address of ten is first placed in $1 ($at), and then the value is loaded from that address.

Perhaps sw would be a better example. In the case of lw I suppose you could've expanded the lw into lui $8, 4097 / lw $8, ($8). But in the case of sw you wouldn't want to overwrite $t0 with the address.