Webcentive RISC-V Reference

c.addi16sp

Add a sign-extended non-zero immediate

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

Encoding

1513121176210
011nzimm[9]00010nzimm[4|6|8:7|5]01

Match 0x6101, mask 0xef83. Source: c.addi16sp c_nzimm10hi c_nzimm10lo 1..0=1 15..13=3 11..7=2 in riscv-opcodes/extensions/rv_c.

FieldBitsriscv-opcodes name
nzimm[9]12c_nzimm10hi
nzimm[4|6|8:7|5]6:2c_nzimm10lo

Description

C.ADDI16SP adds the non-zero sign-extended 6-bit immediate to the value in the stack pointer (sp=x2), where the immediate is scaled to represent multiples of 16 in the range (-512,496). C.ADDI16SP is used to adjust the stack pointer in procedure prologues and epilogues. It expands into addi x2, x2, nzimm[9:4]. C.ADDI16SP is only valid when nzimm ≠ 0; the code point with nzimm=0 is reserved.

Description from riscv-unified-db, reformatted.

Operation

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

X[2] = X[2] + $signed(imm);

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

Specification and related pages