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

ADD Decode And Execute Animation

Uses the same rhythm as the ADDI page: machine-code fields, fixed-field identification, operand reads, instruction-specific execution, and ISA-visible state update.

rd
rs1
rs2
add
,
,
Execution Context
31..25
24..20
19..15
14..12
11..7
6..0
0000000
funct7
00111
rs2
00110
rs1
000
funct3
00101
rd
0110011
opcode
Execution Data Path
instruction
0x007302B3
opcode
0110011 -> OP
funct3
000 -> ADD
funct7
0000000 -> base ALU op
rd / rs1 / rs2
t0(x5) / t1(x6) / t2(x7)
immediate
not used
ALU
0x00000014 + 0x00000007 = 0x0000001B
x5
t0(x5) = 0x0000001B
Current Step

Concept Step: receive the 32-bit instruction encoding

The machine code is split by the current instruction format; the animation starts from encoding/decode.

encoding: 0x007302B3
syntax : add t0(x5), t1(x6), t2(x7)
result : t0(x5) = 0x0000001B

This animation shows ISA-visible decode and state changes, not any specific CPU pipeline, cache, prediction, or timing implementation.

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.