ADD

RISC-V ADD Instruction Details

Instruction ManualR-type

Add rs1 and rs2, place result in rd

ADD is an R-type instruction in the RISC-V RV32I/RV64I base integer set. Its assembly syntax is `add rd, rs1, rs2` — it adds the values in registers rs1 and rs2 and writes the result to rd. Overflow is silently ignored; only the lower XLEN bits are kept (32-bit result on RV32, 64-bit on RV64). ADD uses opcode 0110011 with funct3=000 and funct7=0000000. For immediate addition, use ADDI instead.

Instruction Syntax

add rd, rs1, rs2
Operand Breakdown
Destination rd: register receiving the operation result.
Source rs1: register holding the first operand.
Source rs2: register holding the second operand.
RV32IArithmetic

Instruction Encoding

31..25
funct7
24..20
rs2
19..15
rs1
14..12
funct3
11..7
rd
6..0
opcode

ADD uses opcode 0110011 (0x33), funct3 000, funct7 0000000. The rs1 and rs2 fields select the two source registers, and rd selects the destination register.

Format: R-type
opcode: 0110011 (0x33)
funct3: 000 (0x0)
funct7: 0000000 (0x00)

Instruction Behavior

ADD (R-type) adds rs1 and rs2 (overflow ignored, low XLEN bits retained), writing to rd. funct7=0000000, funct3=000. The most fundamental arithmetic operation in RISC-V. Paired with ADDI for base+offset address computations.

Quick Understanding & Search Notes

ADD is register-to-register integer addition. In RV32I/RV64I semantics it adds rs1 and rs2, writes rd, does not trap on arithmetic overflow, and keeps the XLEN-wide result.

Both source operands come from registers; use ADDI for a small immediate add.
ADD and SUB share opcode and funct3 and are mainly distinguished by funct7.

Official Spec Notes

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

Instruction Comparisons

ADD vs ADDI

ADD takes two register operands (rs1 + rs2), while ADDI takes one register and a 12-bit signed immediate (rs1 + imm). ADD is an R-type instruction (opcode 0110011); ADDI is I-type (opcode 0010011). If you need to add a constant outside the -2048 to 2047 range, load it into a temporary register first (using LUI+ADDI) and then use ADD.

ADD vs SUB

ADD and SUB are both R-type instructions sharing the same opcode (0110011) and funct3 (000). They are distinguished solely by the funct7 field: ADD uses funct7 = 0000000 while SUB uses funct7 = 0100000. In other words, bit 30 of the instruction word selects between addition (bit30=0) and subtraction (bit30=1). RISC-V designed it this way to simplify decode logic and avoid wasting extra opcode space.

Common Usage Scenarios

Address & Pointer

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

Basic Arithmetic

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

Register Operations

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

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is R-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

Overflow is silently ignored, no exception raised
rd=x0 discards result (HINT space); x0 is hardwired to zero
Do not confuse with ADDI: ADD has two register operands, ADDI takes an immediate

FAQ

Does ADD trap on overflow?

No. Base integer addition ignores arithmetic overflow; software must add explicit checks when overflow detection is required.

When should I use ADD instead of ADDI?

Use ADD when both operands are registers. Use ADDI when the second operand is a sign-extended 12-bit immediate.