Home/Instructions/Byte Reverse
REV8

RISC-V REV8 Instruction Details

Instruction ManualI-type

Byte-reverse register (endianness conversion)

Instruction Syntax

rev8 rd, rs
Operand Breakdown
rd, rs: integer registers x0–x31; no immediate operand.
32-bit OP-IMM: opcode=0010011, funct3=101; fixed bits31:20 are 011010011000 (0x698) in RV32 or 011010111000 (0x6B8) in RV64, with no arithmetic-immediate sign extension.
RV32/RV64; requires enabled Zbb or Zbkb; B includes Zbb.
Reverse byte positions across the full XLEN register, preserving bit order inside each byte: four bytes in RV32 or eight in RV64.
x0 is always zero and discards writes; rd may overlap a source, using source values before writeback. Only integer registers are operated on, with no data-memory access.
BZbbZbkbBit ManipulationInteger Operation

Instruction Behavior

Reverse all bytes of integer register rs. RV32 example: 0xAABBCCDD → 0xDDCCBBAA. Fixed imm[11:0] is 0x698 in RV32 and 0x6B8 in RV64, not an arithmetic immediate. Zbb or Zbkb.

REV8 Decode And Execute Animation

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

rd
rs
rev8
,
Execution Context

Assumes Zbb or Zbkb is enabled at the selected XLEN, with the fixed register values below and PC=0x2000; fetch succeeds and no asynchronous interrupt occurs. Steps are a teaching decomposition.

t1(x6)
0x00000014
31..20
19..15
14..12
11..7
6..0
011010011000
fixed imm[11:0]
00110
rs1
101
funct3
00101
rd
0010011
opcode
Execution Data Path
instruction
0x69835293
opcode
0010011 -> OP-IMM
funct3
101 -> REV8
fixed imm[11:0]
011010011000 -> REV8 RV32 selector
rd / rs
t0(x5) / t1(x6)=0x00000014
fixed imm[11:0]
011010011000 -> REV8 RV32 selector (not an arithmetic immediate)
reverse byte order
Not computed
x5
t0(x5) = 0x00003001; pc = 0x00002000
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: 0x69835293
syntax : rev8 t0(x5), t1(x6)
Pending result: Not computed
Current architectural state
t0(x5) = 0x00003001; pc = 0x00002000

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

Quick Understanding & Search Notes

Reverse the byte order across the full XLEN register: four bytes in RV32 or eight in RV64, keeping bit order within each byte.

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
  • rd, rs: integer registers x0–x31; no immediate operand.
  • 32-bit OP-IMM: opcode=0010011, funct3=101; fixed bits31:20 are 011010011000 (0x698) in RV32 or 011010111000 (0x6B8) in RV64, with no arithmetic-immediate sign extension.
Semantic Check
  • RV32/RV64; requires enabled Zbb or Zbkb; B includes Zbb.
  • Reverse byte positions across the full XLEN register, preserving bit order inside each byte: four bytes in RV32 or eight in RV64.
  • x0 is always zero and discards writes; rd may overlap a source, using source values before writeback. Only integer registers are operated on, with no data-memory access.

Pitfalls / Common Confusions

Behavior differs between RV32 and RV64 (byte count)

FAQ

Does REV8 access memory?

No. This instruction reads its integer source registers and writes the computed result to rd; it performs no data-memory load or store.

What is the result width of REV8?

REV8 operates across the complete XLEN-wide register and writes an equally wide result: four bytes in RV32 and eight bytes in RV64.