Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MIPS: The Equivalent of la instruction without using pseudo codes?

Tags:

assembly

mips

The reference says the pseudo code for la (load address) is translated to:

Pseudo : la $1, Label   

lui $1, Label[31:16]
ori $1,$1, label[15:0]

but when I try to assemble the code in MARS I get the error:

"Invalid language element: 16]

and if I remove the [31:16] part I get

"Label": operand is of incorrect type

Any idea?

like image 716
Mehran Avatar asked Mar 01 '23 05:03

Mehran


1 Answers

That means that the 16 most significant bits of label are set in $1. Then, 16 less significant bits are or'ed with the 16 most significant bits.

Here you can find the description of the lui instruction. It loads 16 msb bits of the label address on the register and zeroes 16 lsb.

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

Its in no way intended to be "real code". The [31:16] / [15:0] part is not valid mips, and is only there for you to understand bit movements.

Edit: In response to your comment, you would have to know the address you want to load using the lui instruction. To do this, you could use a label to indicate the desired address. For example

.data 
my_var: .asciiz "This is a nul terminated string"

.text
        andi $a0,$a0,0x0000ffff
        lui $a0,my_var
        ori $a0,$a0,my_var
like image 165
Tom Avatar answered May 11 '23 22:05

Tom