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.
RV32IRV64IArithmetic

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).

ADDI Decode And Execute Animation

Shows a conceptual execution flow: decode opcode/funct3/rd/rs1/imm from the 32-bit I-type encoding, read rs1, sign-extend the immediate, add, then write rd.

rd
rs1
imm
addi
,
,
Execution Context

This example uses fixed initial register values; initial PC=0x00002000, and successful execution advances PC to 0x00002004.

t1(x6)
0x00000014
31..20
19..15
14..12
11..7
6..0
000001100100
imm[11:0]
00110
rs1
000
funct3
00101
rd
0010011
opcode
Execution Data Path
instruction
0x06430293
opcode
0010011 -> OP-IMM
funct3
000 -> ADDI
rd / rs1
x5 / x6
imm
000001100100 -> 100
x6
0x00000014
ALU
Not computed
x5
x5 = 0x00003001
Current Step

Concept Step: receive the 32-bit instruction encoding

The machine code is 0x06430293, split using the I-type field layout.

encoding: 0x06430293
syntax : addi x5, x6, 100
Pending result: Not computed
Current architectural state
x5 = 0x00003001; pc = 0x00002000

This animation shows ADDI ISA-visible decode and execution semantics, not any specific CPU pipeline, decode stage count, or timing.

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 with the exact encodable range -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

RV32I/RV64I example: with a1=0x1000, addi a0, a1, 16 produces a0=0x1010; the addition itself does not access memory.

Basic Arithmetic

RV32I/RV64I example: with a1=0x1000, addi a0, a1, 16 produces a0=0x1010; the addition itself does not access memory.

Immediates & Constants

RV32I/RV64I example: with a1=0x1000, addi a0, a1, 16 produces a0=0x1010; the addition itself does not access memory.

Register Operations

RV32I/RV64I example: with a1=0x1000, addi a0, a1, 16 produces a0=0x1010; the addition itself does not access memory.

Pre-Use Checklist

Syntax Check
  • Register operands select x0 through x31; ABI register names are aliases for those registers.
  • The signed 12-bit immediate encodes -2048 through 2047, including both endpoints.
Semantic Check
  • rs1 plus the sign-extended immediate keeps the low XLEN bits; arithmetic overflow raises no exception and x0 writes are discarded.

Pitfalls / Common Confusions

The signed 12-bit immediate must be -2048 through 2047; values outside this range cannot be encoded in one ADDI
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 with the exact encodable range -2048 through 2047. Values outside this range cannot be placed directly in this immediate field.

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.