Home/Instructions/XOR Immediate
XORI

RISC-V XORI Instruction Details

Instruction ManualI-type

Bitwise XOR of rs1 with sign-extended 12-bit immediate, result in rd

Instruction Syntax

xori rd, rs1, imm
Operand Breakdown
Destination rd: general-purpose register receiving the result.
Source rs1: register holding the first operand.
Immediate imm: 12-bit signed value, sign-extended before operation with rs1.
RV32ILogical

Instruction Encoding

31..20
imm[11:0]
19..15
rs1
14..12
funct3
11..7
rd
6..0
opcode

XORI uses opcode 0010011 (0x13), funct3 100. 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: 100 (0x4)

Instruction Behavior

XORI performs bitwise XOR of rs1 with the sign-extended 12-bit immediate, writing to rd. XORI rd,rs1,-1 inverts all bits of rs1 (pseudo NOT). Common for bit flipping, data encryption/checksum, register clearing, and complement generation.

Quick Understanding & Search Notes

XORI is a base integer bitwise logical instruction. It operates across XLEN bits; immediate forms use a sign-extended 12-bit immediate.

The I-type immediate is sign-extended to XLEN before the bitwise operation.
Integer logical operations do not raise arithmetic-overflow exceptions; rd=x0 discards the result.

Common Usage Scenarios

Bit Operations & Masks

Understand this scenario with real code like «xori x5, x6, -1 # x5 = ~x6 (bitwise NOT)».

Crypto & Security

Understand this scenario with real code like «xori x5, x6, -1 # x5 = ~x6 (bitwise NOT)».

Logical Operations

Understand this scenario with real code like «xori x5, x6, -1 # x5 = ~x6 (bitwise NOT)».

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is I-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

Immediate range is 12-bit signed; for larger masks, load into a register first

FAQ

Is the immediate zero-extended?

XORI immediate forms use a 12-bit signed immediate that is sign-extended to XLEN.

Does it update flags?

The base integer ISA has no condition-code flags; only rd is written.