Home/Instructions/Add Immediate
ADDI

RISC-V ADDI Instruction Details

Instruction ManualI-type

Add sign-extended 12-bit immediate to rs1, place result in rd

Instruction Syntax

addi rd, rs1, imm
Operand Breakdown
Destination rd: general-purpose register receiving the result.
Source rs1: register holding the first operand.
Immediate imm: 12-bit signed value, sign-extended before operation with rs1.
RV32IArithmetic

Instruction Encoding

31..20
imm[11:0]
19..15
rs1
14..12
funct3
11..7
rd
6..0
opcode

ADDI uses opcode 0010011 (0x13), funct3 000. The rs1 field selects the source register, the 12-bit immediate provides the second operand, and rd selects the destination.

Format: I-type
opcode: 0010011 (0x13)
funct3: 000 (0x0)

Instruction Behavior

ADDI (I-type, opcode=0010011, funct3=000) adds the sign-extended 12-bit immediate to rs1 (overflow ignored, low XLEN bits retained) and writes to rd. ADDI x0,x0,0 is the canonical NOP encoding. ADDI rd,x0,imm loads a small immediate (pseudo LI). ADDI rd,rs1,0 copies a register (pseudo MV).

Quick Understanding & Search Notes

ADDI adds a sign-extended 12-bit immediate to rs1 and writes rd. It is the common base form for small constants, stack adjustment, address offsets, and move-like pseudo-instructions.

The immediate is a signed 12-bit value, typically covering -2048 through 2047.
ADDI x0, x0, 0 is the canonical NOP encoding.

Official Spec Notes

These notes are checked against the RISC-V Unprivileged ISA manual and summarize operation semantics, immediate ranges, and edge behavior.

Common Usage Scenarios

Address & Pointer

Understand this scenario with real code like «addi x5, x6, 100 # x5 = x6 + 100».

Basic Arithmetic

Understand this scenario with real code like «addi x5, x6, 100 # x5 = x6 + 100».

Immediates & Constants

Understand this scenario with real code like «addi x5, x6, 100 # x5 = x6 + 100».

Register Operations

Understand this scenario with real code like «addi x5, x6, 100 # x5 = x6 + 100».

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is I-type.
  • Confirm the operand order matches the example.
Semantic Check
  • Ensure the destination register usage is compatible with the calling convention.
  • Confirm this is not the lower-level form of a pseudo-instruction expansion.

Pitfalls / Common Confusions

Immediate is 12-bit signed (range -2048 to +2047); for larger values use LUI+ADDI combo
ADDI rd, x0, imm acts as LI pseudo (sign-extends immediate to XLEN)
ADDI rd, rs1, 0 acts as MV pseudo; note first operand is rd, not rs1
Overflow is silently ignored, no exception raised

FAQ

What is the ADDI immediate range?

ADDI uses a sign-extended 12-bit immediate, typically -2048 to 2047. Larger constants require sequences such as LUI/AUIPC plus ADDI.

Does RISC-V have SUBI?

No separate SUBI exists in the base integer set. Subtract a small constant by using ADDI with a negative immediate.