MIPS "la" pseudo instruciton

darksky picture darksky · Nov 28, 2011 · Viewed 25.6k times · Source

In MIPS, the la instruction translates into lui and ori. However, MARS Simulator does not seem to do that at all. When I dump the following machine code:

.text
    la $a0, array
    la $a1, array_size
    lw $a1, 0($a1)

.data
    array: .word 0:10
    array_size: .word 10
    message: .asciiz "The sum of numbers in array is: "

I get:

00100000000001000010000000000000
00100000000001010010000000101000
10001100101001010000000000000000

Which is obviously. It is dumping la as one instruction. What does MARS do? How can I make it interpret la as lui and ori?

Thank you,

Answer

duskwuff -inactive- picture duskwuff -inactive- · Nov 28, 2011

What's happening here is that your assembler is compiling these las as addi $<dest>, $0, <value>. The two-instruction sequence is only required for values which can't be represented in a 16-bit immediate; the values you're using here look like 0x2000 and 0x2028, so they fit in a single instruction.

How can I make it interpret la as lui and ori?

Load bigger constants. :) Your assembler might also have an option to force the use of the full sequence even when it's unnecessary.