Webcentive RISC-V Reference

c.addi4spn

Add a zero-extended non-zero immediate, scaled by 4, to the stack pointer

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

Encoding

15131254210
000nzuimm[5:4|9:6|2|3]rd′00

Match 0x0000, mask 0xe003. Source: c.addi4spn rd_p c_nzuimm10 1..0=0 15..13=0 in riscv-opcodes/extensions/rv_c.

FieldBitsriscv-opcodes name
nzuimm[5:4|9:6|2|3]12:5c_nzuimm10
rd′4:2rd_p

Description

Adds a zero-extended non-zero immediate, scaled by 4, to the stack pointer, x2, and writes the result to xd'. This instruction is used to generate pointers to stack-allocated variables. It expands to addi xd', x2, nzuimm[9:2]. C.ADDI4SPN is only valid when nzuimm ≠ 0; the code points with nzuimm=0 are reserved.

Description from riscv-unified-db, reformatted.

Operation

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

X[creg2reg(xd)] = X[2] + imm;

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

Specification and related pages