Webcentive RISC-V Reference

c.lwsp

Load word from stack pointer

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

Encoding

1513121176210
010uimm[5]rd≠0uimm[4:2|7:6]10

Match 0x4002, mask 0xe003. Source: c.lwsp rd_n0 c_uimm8sphi c_uimm8splo 1..0=2 15..13=2 in riscv-opcodes/extensions/rv_c.

FieldBitsriscv-opcodes name
uimm[5]12c_uimm8sphi
rd≠011:7rd_n0
uimm[4:2|7:6]6:2c_uimm8splo

Description

Loads a 32-bit value from memory into register xd. It computes an effective address by adding the zero-extended offset, scaled by 4, to the stack pointer, x2. It expands to lw xd, offset(x2). C.LWSP is only valid when xd ≠ x0. The code points with xd=x0 are reserved.

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;

X[xd] = sext(read_memory(32, virtual_address, $encoding), 32);

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

Specification and related pages