ISA & Assembly
What is the difference between the RISC-V "add" and "addi" instructions?
- Aadd adds integers; addi adds floating-point numbers
- Badd adds values in memory; addi adds register values
- Cadd adds two registers; addi adds a register and a constant written in the instruction (an immediate)
Show answer and explanation
Answer: C. add adds two registers; addi adds a register and a constant written in the instruction (an immediate)
"add rd, rs1, rs2" puts the sum of two registers into rd, and "addi rd, rs1, imm" adds a register and a 12-bit constant (an immediate) embedded in the instruction. An immediate saves the step of first loading the constant into a register. RISC-V has no subtract-immediate instruction; it subtracts by adding a negative immediate, as in "addi t0, t0, -1".
- A. Floating-point addition uses separate instructions such as fadd.s.
- B. RISC-V arithmetic never accesses memory directly.
- C. Correct. The i stands for immediate.