xori
xori
rd, rs1, imm
rd = rs1 ^ imm
R
31–25funct7
24–20rs2
19–15rs1
14–12funct3
11–7rd
6–0opcode
I
31–20imm[11:0]
19–15rs1
14–12funct3
11–7rd
6–0opcode
S
31–25imm[11:5]
24–20rs2
19–15rs1
14–12funct3
11–7imm[4:0]
6–0opcode
B
31–25imm[12,10:5]
24–20rs2
19–15rs1
14–12funct3
11–7imm[4:1,11]
6–0opcode
U
31–12imm[31:12]
11–7rd
6–0opcode
J
31–12imm[20,10:1,11,19:12]
11–7rd
6–0opcode

xori is bitwise XOR with a constant, completing the set of immediate logic instructions alongside andi and ori. The i suffix means immediate — a fixed value written into the instruction rather than read from a second register. The XOR rule is the difference detector: at each bit position the result is 1 when the two bits differ (see the xor page). Against a constant mask, that rule becomes a toggle: every 1 in the mask flips the matching bit, every 0 leaves it alone.

The form is xori rd, rs1, imm: XOR the value in rs1 against the constant imm and write the result to rd. So where andi clears chosen bits and ori sets them, xori inverts them — and inverting twice returns the original.

Its most important use builds another instruction entirely. Flipping *every* bit of a value is just XOR against a mask of all 1s, and that is exactly what the not instruction does — it is shorthand for xori rd, rs, -1, since -1 in bits is all 1s. RISC-V has no separate invert-everything instruction because this one covers it.

A common small use is toggling a yes/no value stored as 0 or 1: xori t0, t0, 1 flips it to the other state each time. The constant is limited to 12 bits; for wider patterns, load the mask into a register and use the register form xor.