Home/Instructions/Byte Reverse
REV8

RISC-V REV8 Instruction Details

Instruction ManualR-type

Byte-reverse register (endianness conversion)

Instruction Syntax

rev8 rd, rs1
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..20
imm[11:0]
19..15
rs1
14..12
funct3
11..7
rd
6..0
opcode

REV8 uses opcode 0010011 (0x13), funct3 101, funct7 0110100. The rs1 field selects the source register, the 12-bit immediate provides the second operand, and rd selects the destination.

Format: I-type
opcode: 0010011 (0x13)
funct3: 101 (0x5)
funct7: 0110100 (0x34)

Instruction Behavior

Byte-reverse: reverses the byte order of rs. RV32: rev8(0xAABBCCDD)=0xDDCCBBAA. REV8(RV32) and REV8(RV64) have different funct7. Part of Zbb and Zbkb.

Quick Understanding & Search Notes

REV8 is a B/Zbb instruction for reverse byte order across XLEN. This page is checked against the official B extension semantics, with emphasis on XLEN, W suffixes, .uw suffixes, and bitwise or rotate boundaries.

RV32 reverses 4 bytes and RV64 reverses 8 bytes.
REV8 swaps byte positions; do not confuse it with BREV8, which reverses bits within each byte.

Common Usage Scenarios

Network & Byte Order

Understand this scenario with real code like «rev8 x10, x11 ; byte-reverse x11 (bswap)».

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

Behavior differs between RV32 and RV64 (byte count)

FAQ

Does REV8 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 REV8?

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.