Where does the SLL shift amount come from?
For register shifts, the amount comes from the low log2(XLEN) bits of rs2.
Shift rs1 left logically by the low log2(XLEN) bits of rs2, result in rd
SLL uses opcode 0110011 (0x33), funct3 001, funct7 0000000. The rs1 and rs2 fields select the two source registers, and rd selects the destination register.
SLL shifts rs1 left logically by the amount in the low log2(XLEN) bits of rs2 (rs2[4:0] on RV32, rs2[5:0] on RV64), filling LSBs with zeros. Result in rd. funct7=0000000, funct3=001. Unlike SLLI (immediate shift), SLL allows a variable shift amount from a register.
SLL performs a logical left shift, fills low bits with zeros, and writes rd. The shift amount comes from the low log2(XLEN) bits of rs2.
Understand this scenario with real code like «sll x5, x6, x7 # x5 = x6 << (x7[4:0])».
Understand this scenario with real code like «sll x5, x6, x7 # x5 = x6 << (x7[4:0])».
For register shifts, the amount comes from the low log2(XLEN) bits of rs2.
Logical right shift fills high bits with zeros. Arithmetic right shift copies the original sign bit, which is usually used to preserve signedness.