user1710563
user1710563

Reputation: 387

How is the la instruction translated in MIPS?

I know la in MIPS breaks down to lui and ori but what are the arguments for those instructions?

I looked at this question here MIPS Pseudo istructions, replacements but does the resulting lui always use 4097?

Consider the following:

       .data
_a:    .space    4
       .text
main:  la       $s0,_a

Does that get translated to this?

lui    $at,4097
ori    $s0,$at,0

Thank you!

Upvotes: 1

Views: 1878

Answers (2)

Craig Estey
Craig Estey

Reputation: 33601

4097 decimal is 0x1001. This is the upper 16 bits of 0x10010000.

This is the default load address for the start of the .data segment in the mars simulator.

If you had done la $s0,main, the lui would be lui $at,0x0040 because the default start address for .text is 0x00400000.

To see the difference, try this program:

       .data
_a:    .space    100000
_b:    .space    4
       .text
main:  la       $s0,_b

Upvotes: 2

markgz
markgz

Reputation: 6266

The lui loads the upper 16 bits of the address, and the ori loads the lower 16 bits of the address. The address can be any 32 bit value, so the lui typically does not load 4097.

Upvotes: 0

Related Questions