c.lwsp

Load word from stack pointer

This instruction is defined by:

Encoding

svg

Synopsis

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

Access

M

HS

U

VS

VU

Always

Always

Always

Always

Always

Decode Variables

Bits<8> imm = {$encoding[3:2], $encoding[12], $encoding[6:4], 2'd0};
Bits<5> rd = $encoding[11:7];

Execution

  • Pruned, XLEN == 64

  • Original

if ((%%LINK%csr_field;misa.C;CSR[misa].C%% == 1'b0)) {
  %%LINK%func;raise;raise%%(ExceptionCode::IllegalInstruction, %%LINK%func;mode;mode%%(), $encoding);
}
XReg virtual_address = X[2] + imm;
X[rd] = %%LINK%func;sext;sext%%(%%LINK%func;read_memory;read_memory%%<32>(virtual_address, $encoding), 32);
if (%%LINK%func;implemented?;implemented?%%(ExtensionName::C) && (%%LINK%csr_field;misa.C;CSR[misa].C%% == 1'b0)) {
  %%LINK%func;raise;raise%%(ExceptionCode::IllegalInstruction, %%LINK%func;mode;mode%%(), $encoding);
}
XReg virtual_address = X[2] + imm;
X[rd] = %%LINK%func;sext;sext%%(%%LINK%func;read_memory;read_memory%%<32>(virtual_address, $encoding), 32);

Exceptions

This instruction may result in the following synchronous exceptions:

  • IllegalInstruction

  • LoadAccessFault

  • LoadPageFault