Webcentive RISC-V Reference

c.addi

Add a sign-extended non-zero immediate

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

Encoding

1513121176210
000nzimm[5]rd/rs≠0nzimm[4:0]01

Match 0x0001, mask 0xe003. Source: c.addi rd_rs1_n0 c_nzimm6lo c_nzimm6hi 1..0=1 15..13=0 in riscv-opcodes/extensions/rv_c.

FieldBitsriscv-opcodes name
nzimm[5]12c_nzimm6hi
rd/rs≠011:7rd_rs1_n0
nzimm[4:0]6:2c_nzimm6lo

Description

C.ADDI adds the non-zero sign-extended 6-bit immediate to the value in register xd then writes the result to xd. C.ADDI expands into addi xd, xd, imm. C.ADDI is only valid when xd ≠ x0 and imm ≠ 0. The code points with xd=x0 encode the C.NOP instruction; the remaining code points with imm=0 encode HINTs.

Description from riscv-unified-db, reformatted.

Operation

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

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

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

Specification and related pages