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.

Encoding

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

Operands

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

Example

CSRRW x10, scause, x11

// Writes x11 to 'scause' CSR and reads old 'scause' into x10.

Related

More in Zicsr

Description

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.

Operation

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