CSRRW

Control Status Register Read/Write

CSRRW rd, csr, rs1

Atomically swaps values in the CSRs. Reads the old value of the CSR into rd, then writes rs1 to the CSR.

Details

CSRRW atomically reads the value of CSR csr into rd, then writes the value from rs1 into the CSR. If rd is x0, the read is skipped and no side-effects from reading occur.

Pseudocode Operation

t = CSRs[csr]; CSRs[csr] = R[rs1]; R[rd] = t;

Example

CSRRW x10, scause, x11

Encoding

Binary Layout
csr
31:20
rs1
19:15
001
14:12
rd
11:7
1110011
6:0
 
Format I-Type
Opcode 0x73
Extension Zicsr

Operands

  • rd
    Dest (Old Value)
  • csr
    CSR Address
  • rs1
    Src (New Value)