addi
lyszt.net covers addi and other RISC-V instructions in more detail.
Encoding format
Description
Adds a constant to a register. In addi rd, rs1, imm, the constant imm is added to the value in rs1 and the result goes to rd. The constant is signed and spans -2048 to 2047, and larger values must first be placed in a register with li. A negative constant turns the addition into a subtraction, as in the counter decrement addi t0, t0, -1.
Official definition
Most integer computational instructions operate on XLEN bits of values held in the integer register file. Integer computational instructions are either encoded as register-immediate operations using the I-type format or as register-register operations using the R-type format. The destination is register rd for both register-immediate and register-register instructions. No integer computational instructions cause arithmetic exceptions.
Integer Register-Immediate Instructions
ADDI adds the sign-extended 12-bit immediate to register rs1. Arithmetic overflow is ignored and the result is simply the low XLEN bits of the result. ADDI rd, rs1, 0 is used to implement the MV rd, rs1 assembler pseudoinstruction.
References
- [1]RISC-V International. The RISC-V Instruction Set Manual, Volume I: Unprivileged Architecture. Version 20260120. Section 2.4.1, Integer Register-Immediate Instructions, pages 28 to 29.
- [2]RISC-V International. The RISC-V Instruction Set Manual, Volume I: Unprivileged Architecture. Version 20260120. Section 2.4, Integer Computational Instructions, page 27.