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.
BZbbZbkbBit ManipulationInteger Operation

Instruction Behavior

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

ROR Decode And Execute Animation

Starts with machine-code field decoding, then shows operand reads, instruction-specific execution, and ISA-visible state update.

rd
rs1
rs2
ror
,
,
Execution Context
a0(x10)
0x00001000
31..25
24..20
19..15
14..12
11..7
6..0
0110000
funct7
00110
rs2
01010
rs1
101
funct3
00101
rd
0110011
opcode
Execution Data Path
instruction
0x606552B3
opcode
0110011 -> OP
funct3
101 -> ROR
funct7
0110000 -> ROR selector
rd / rs1 / rs2
t0(x5) / a0(x10)=0x00001000 / t1(x6)[4:0]=20
rotate right
ror(0x00001000, 20) -> 0x01000000
x5
t0(x5) = 0x01000000
Current Step

Concept Step: receive the 32-bit instruction encoding

The machine code is split by the current instruction format; the animation starts from encoding/decode.

encoding: 0x606552B3
syntax : ror t0(x5), a0(x10), t1(x6)
result : t0(x5) = 0x01000000
Architectural Result
t0(x5) = 0x01000000

This animation shows ISA-visible decode and state changes, not any specific CPU pipeline, cache, prediction, or timing implementation.

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
  • Verify rd, rs1, rs2 (and rs3) are valid GPRs.
  • Confirm funct3 and funct7 encoding is correct.
Semantic Check
  • Check if the result affects subsequent branches or address calculations.
  • Ensure the rd register is not overwritten by another instruction.

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?

ROR rotates at the complete XLEN width and writes an equally wide result to rd: rs2[4:0] in RV32 and rs2[5:0] in RV64.