Webcentive RISC-V Reference

c.swsp

Store word to stack

Extension
C
XLEN
RV32 and RV64
Assembly (riscv-unified-db)
c.swsp xs2, imm(sp)
Length
16-bit (compressed)

Encoding

15131276210
110uimm[5:2|7:6]rs210

Match 0xc002, mask 0xe003. Source: c.swsp c_rs2 c_uimm8sp_s 1..0=2 15..13=6 in riscv-opcodes/extensions/rv_c.

FieldBitsriscv-opcodes name
uimm[5:2|7:6]12:7c_uimm8sp_s
rs26:2c_rs2

Description

Stores a 32-bit value in register xs2 to memory. It computes an effective address by adding the zero-extended offset, scaled by 4, to the stack pointer, x2. It expands to sw xs2, offset(x2).

Description from riscv-unified-db, reformatted.

Operation

if (implemented?(ExtensionName::C) && MISA_CSR_IMPLEMENTED && (CSR[misa].C == 1'b0)) {
  reserved_instruction($encoding);
}

XReg virtual_address = X[2] + imm;

write_memory(32, virtual_address, X[xs2][31:0], $encoding);

Pseudocode in riscv-unified-db’s IDL, quoted unchanged.

Specification and related pages