Home/Instructions/Rotate Right
ROR

RISC-V ROR Instruction Details

Instruction ManualR-type

Rotate right by register

Instruction Syntax

ror rd, rs1, rs2
Operand Breakdown
Destination rd: register receiving the operation result.
Source rs1: register holding the first operand.
Source rs2: register holding the second operand.
BZbbBit ManipulationInteger Operation

Instruction Encoding

31..25
funct7
24..20
rs2
19..15
rs1
14..12
funct3
11..7
rd
6..0
opcode

ROR uses opcode 0110011 (0x33), funct3 101, funct7 0110000. The rs1 and rs2 fields select the two source registers, and rd selects the destination register.

Format: R-type
opcode: 0110011 (0x33)
funct3: 101 (0x5)
funct7: 0110000 (0x30)

Instruction Behavior

Rotates rs1 right by the lower log2(XLEN) bits of rs2. Part of Zbb and Zbkb. Replaces four-instruction sequence.

Quick Understanding & Search Notes

ROR is a B/Zbb instruction for XLEN-wide rotate right. This page is checked against the official B extension semantics, with emphasis on XLEN, W suffixes, .uw suffixes, and bitwise or rotate boundaries.

The rotate amount comes from the low log2(XLEN) bits of rs2.
Rotates wrap shifted-out bits around to the other end; they are not logical shifts.

Common Usage Scenarios

Comparison & Detection

Understand this scenario with real code like «ror x10, x11, x12 ; x10 = rotr(x11, x12 & (XLEN-1))».

Crypto & Security

Understand this scenario with real code like «ror x10, x11, x12 ; x10 = rotr(x11, x12 & (XLEN-1))».

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is R-type.
  • Confirm the operand order matches the example.
Semantic Check
  • Ensure the destination register usage is compatible with the calling convention.
  • Confirm this is not the lower-level form of a pseudo-instruction expansion.

Pitfalls / Common Confusions

Shift amount is modulo XLEN

FAQ

Does ROR access memory?

No. It only reads and writes integer registers; any memory access must be performed by a separate load or store instruction.

What is the result width of ROR?

Except that W-suffixed forms produce a 32-bit result then sign-extend and .uw forms first extract a 32-bit unsigned operand, the result is written to rd at XLEN width.