Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MIPS: li vs. add/addi

1,616 views
Skip to first unread message

Norman Lee

unread,
Mar 1, 2008, 5:10:33 PM3/1/08
to
The li instruction lets you store a full 32-bit number in a register,
but if you don't need all those bits, is it equivalent to using add or addi?

Basically, could this:
> li $a0, 8 # allocate 8 bytes
> li $v0, 9 # set the appropriate syscall code

be replicated with this:
> addi $a0 $0 8
> addi $v0 $0 9

or this?
> addi $t0 $0 8
> addi $t1 $0 9
> add $a0 $0 $t0
> add $v0 $0 $t1

[TA] Matt Johnson

unread,
Mar 1, 2008, 6:43:59 PM3/1/08
to
Right. If you check your green sheet, there is no official li
instruction in the core instruction set because it's "squishy" MIPS
that the assembler would expand for you into the hard, ugly, "real"
MIPS. It would either expand an li into an addi like this one (in the
case of 16 bit immediates):

li $t0 0xDEAD --> addi $t0 $0 0xDEAD

Or it would do the following for a larger immediate:

li $t0 0xDEADBEEF -->

lui $t0 0xDEAD
ori $t0 $t0 0xBEEF


Matt

On 2008-03-01 14:13:44 -0800, cs61...@imail.EECS.Berkeley.EDU (Daniel
Christopher Ritchie) said:

> Yes, I believe all of these are equivalent.
>
> In article <fqck8o$jom$1...@geode.berkeley.edu>, Norman Lee <nl...@berkeley.edu>

0 new messages