简体   繁体   中英

Putting a new value into a register with lui (load upper immediate) and ori (OR immediate) [MIPS]

[MIPS]
Assume there is the stored value 0x12345678 in $s0 .

Let's assume I want to put now another value into $s0 (say for example 0x87654321), then I have to put the value in two steps (at least I have learned it this way) with the lui operation and the ori .

lui $s0, 0x8765
ori $s0, $s0, 0x4321

I know this works if $s0 is 0 at the beginning, but I'm actually not sure if the lui operation sets the second half to 0's or if it just replaces the first half with my new input 0x8765.

So, my question is:
Does it work even if there's a stored value in $s0 or do I have to set the value of $s0 to 0 and then set the upper half and lower half ?

You should always consult an instruction set reference about such issues. Or you could even just try it.

But to answer your question, yes, lui clears the low bits.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM