Where does the SRLI shift amount come from?
For immediate shifts, the amount comes from the shamt field; in RV32I it is 5 bits.
Shift rs1 right logically by shamt bits (zeros into MSBs), result in rd
SRLI uses opcode 0010011 (0x13), funct3 101, funct7 0000000. The rs1 field selects the source register, the 12-bit immediate provides the second operand, and rd selects the destination.
SRLI (I-type variant, opcode=0010011, funct3=101, funct7=0000000) shifts rs1 right logically by shamt (lower 5 bits of immediate), filling upper bits with zeros. Result in rd. For RV32I, funct7 bit30=0 (encoding 0000000), which distinguishes it from SRAI (bit30=1).
SRLI performs a immediate logical right shift, fills high bits with zeros, and writes rd. The shift amount comes from the shamt immediate field.
Understand this scenario with real code like «srli x5, x6, 2 # x5 = x6 >> 2 (unsigned divide by 4)».
Understand this scenario with real code like «srli x5, x6, 2 # x5 = x6 >> 2 (unsigned divide by 4)».
Understand this scenario with real code like «srli x5, x6, 2 # x5 = x6 >> 2 (unsigned divide 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.