Learning RiscV my lecturer defined a new command called Load Upper Immediate (lui) like this:
lui rt, imm
loads the lower halfword of the immediate imm into the upper halfword of register rt. The lower bits of the register are set to 0.
with the following image:

But there are few things which I can't understand:
"loads the lower halfword of the immediate" what does this mean? I think if we have 32 bits in imm then it loads the first 16 am I right?
Is the image correct at all? shouldn't the first half be all zeroes and the difination mentions? why we have those 0xf, 0, rt and where rt came from?
Given the following command:
lui S0, 0x1234
What will it do? I don't know the value of location 1234 in memory...
Yes, it is correct; however, that image shows us it's a MIPS instruction, not RISC V1.
The 0xf is the MIPS opcode for
lui. There is an unused field of 5 bits (the zeros) and a register field along with the 16-bit immediate.luiis not a memory reference instruction — it merely loads a constant stored in the instruction into the register.You can look it up in the MIPS green sheet.
Suffice it to say that using 2 instructions we can form a 32-bit constant value (data value or memory address). The first instruction,
luiforms the upper 16 bits of the 32-bit value and the 2nd instruction supplies the lower 16 bits using an ordinaryorioraddi.This one instruction is equivalent to the 2 instruction sequence:
Footnote 1: Here's the RISC V version of
LUI:Quite different as you can see: the immediate is 20 bits long (not MIPS' 16-bits), and, of course, the opcode is on the right (and 7 bits not MIPS' 6 bits). (There are also no wasted zeros.)