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

Instruction Behavior

ADD uses R-type encoding (opcode=0110011, funct7=0000000, funct3=000). It adds integer registers rs1 and rs2, writes the low XLEN bits to rd, and raises no arithmetic-overflow exception. A write to rd=x0 is discarded; x0 remains zero.

ADD Decode And Execute Animation

Starts with machine-code field decoding, then shows operand reads, instruction-specific execution, and ISA-visible state update.

rd
rs1
rs2
add
,
,
Execution Context

This example uses fixed initial register values and PC=0x2000; instruction fetch succeeds, with no asynchronous interrupt or extra extension checks. Exception branches stop ordinary commit; post-trap PC and handler state are EEI-dependent.

t1(x6)
0x00000014
t2(x7)
0x00000007
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)
ALU
Not computed
x5
t0(x5) = 0x00003001; pc = 0x00002000
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 x5, x6, x7
Pending result: Not computed
Current architectural state
t0(x5) = 0x00003001; pc = 0x00002000

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 R-type (opcode 0110011); ADDI is I-type (opcode 0010011). ADDI's encodable immediate range is -2048 through 2047; ADD reads its second addend from rs2 rather than an immediate.

ADD vs SUB

ADD and SUB are R-type instructions sharing opcode=0110011 and funct3=000. ADD has funct7=0000000 and computes rs1+rs2; SUB has funct7=0100000 and computes rs1-rs2. Both keep the low XLEN bits and raise no arithmetic-overflow exception.

Common Usage Scenarios

Address & Pointer

Understand this scenario with real code like «add x5, x6, x7 # RV32I/RV64I: x6=20, x7=7 -> x5=27».

Basic Arithmetic

Understand this scenario with real code like «add x5, x6, x7 # RV32I/RV64I: x6=20, x7=7 -> x5=27».

Register Operations

Understand this scenario with real code like «add x5, x6, x7 # RV32I/RV64I: x6=20, x7=7 -> x5=27».

Pre-Use Checklist

Syntax Check
  • Register operands select x0 through x31; ABI register names are aliases for those registers.
  • ADD uses rd, rs1, and rs2 register fields and has no immediate operand.
Semantic Check
  • rs1+rs2 keeps the low XLEN bits; arithmetic overflow raises no exception and x0 writes are discarded.

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.