Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MIPS “la” pseudo instruction

Tags:

mips

can someone explain to me why MARS translate the pseudo instruction into two instructions: lui & ori? Is there cases when the translation is to only one instruction?

like image 442
kicklog Avatar asked Oct 22 '25 14:10

kicklog


1 Answers

This simple program

.data               
msg: .asciiz "This is a string"
.text
   la  $a0, msg    # pseudo-instruction to load the address of the label str

Translates to the instructions

 Address    Code        Basic                     Source

0x00400000  0x3c011001  lui $1,0x00001001     4       la  $a0, msg    # pseudo-instruction to load the address of the label str
0x00400004  0x34240000  ori $4,$1,0x00000000  

And its always these two instructions AFAIK. The lui instruction makes the immediate value shifted left 16 bits and stored in the register. The lower 16 bits are zeroes.

This way, you can load 32 bit address (in mips32) with 32 bit instructions.

like image 104
Niklas Rosencrantz Avatar answered Oct 25 '25 20:10

Niklas Rosencrantz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!