# RISC-V assembly lui?

In RISC-V assembly I wrote:

addi s0,x0,0x20000


Is this legal such that the assembler will prove the command and make it work right or I'm forced to change it to:

lui s0,0x20


Can someone kindly explain what lui does?

• I strongly suggest that for questions like this you write little snippets of code and try them out. Even if you don't have a RISC V chip lying around, there should be emulators. The reason I suggest this is that you generally learn the answer to your question, plus about half a dozen other questions -- and their answers, eventually -- that you didn't know to ask. – TimWescott Jan 28 at 0:13
• what part of the risc-v documentation do you not understand? – old_timer Jan 28 at 23:36

However, ADDI with x0 as the source register is valid for loading smaller immediate values, so you could do ADDI s0, x0, #0x123, for example. NOP is also implemented this way, and is just a pseudo-instruction for ADDI x0, x0, #0x0. Other forms of NOP (for example adding 0 to a register other than x0) are considered non-canonical and are not recommended because they may be redefined to be a different, meaningful instruction in the future.