Where does the SLLI shift amount come from?
For immediate shifts, the amount comes from the shamt field; in RV32I it is 5 bits.
Shift rs1 left logically by shamt bits (zeros into LSBs), result in rd
SLLI uses opcode 0010011 (0x13), funct3 001, funct7 0000000. The rs1 field selects the source register, the 12-bit immediate provides the second operand, and rd selects the destination.
SLLI (I-type variant, opcode=0010011, funct3=001, funct7=0000000) shifts rs1 left by shamt (encoded in the lower 5 I-immediate bits, inst[24:20]), with zeros shifted into the lower bits. Result in rd. For RV32I, shamt range is 0-31. funct7 upper bits must be all zeros (0000000), bit30=0.
SLLI performs a immediate logical left shift, fills low bits with zeros, and writes rd. The shift amount comes from the shamt immediate field.
Understand this scenario with real code like «slli x5, x6, 2 # x5 = x6 << 2 (multiply by 4)».
Understand this scenario with real code like «slli x5, x6, 2 # x5 = x6 << 2 (multiply by 4)».
For immediate shifts, the amount comes from the shamt field; in RV32I it is 5 bits.
Logical right shift fills high bits with zeros. Arithmetic right shift copies the original sign bit, which is usually used to preserve signedness.