srl
srl
rd, rs1, rs2
rd = rs1 >>> (rs2 & 31)
R
31–25funct7
24–20rs2
19–15rs1
14–12funct3
11–7rd
6–0opcode
I
31–20imm[11:0]
19–15rs1
14–12funct3
11–7rd
6–0opcode
S
31–25imm[11:5]
24–20rs2
19–15rs1
14–12funct3
11–7imm[4:0]
6–0opcode
B
31–25imm[12,10:5]
24–20rs2
19–15rs1
14–12funct3
11–7imm[4:1,11]
6–0opcode
U
31–12imm[31:12]
11–7rd
6–0opcode
J
31–12imm[20,10:1,11,19:12]
11–7rd
6–0opcode

srl shifts bits in the other direction from sll — to the right. Its name is short for shift right logical. The form srl rd, rs1, rs2 slides the bits of rs1 right by the number of places in rs2 and writes the result to rd. Bits that fall off the right edge are discarded, and the empty positions opening up on the left are filled with 0s.

That zero-fill is the defining detail, and it earns the word logical. If sliding left doubles a number, sliding right halves it: shift right by 1 to divide by 2, by 3 to divide by 8. The leftover remainder is simply dropped, exactly like integer division. This makes srl the fast way to divide an unsigned number by a power of two.

The word unsigned is the catch, and it leads to the one thing you must watch. There are two right-shift instructions, and they differ only in what they pour into the vacated top bits. srl always pours in 0s. Its sibling sra pours in copies of the sign bit instead, which keeps negative numbers negative. For a value you are treating as a plain pattern of bits, or as a number that is never negative, srl is correct. For a signed number that might be negative, srl would turn it into a large positive value — there you want sra.

For a fixed shift amount, use the constant form srli.