ISA & Assembly

What is the difference between the RISC-V "add" and "addi" instructions?

  1. Aadd adds integers; addi adds floating-point numbers
  2. Badd adds values in memory; addi adds register values
  3. 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.
Practice this topic Back to topic

More ISA & Assembly questions

  1. After running the RISC-V code above, what is the value in register a2?
  2. What does the RISC-V instruction "lw t0, 8(sp)" do?
  3. In the RISC-V conditional branch "beq a0, a1, label", how is the target address of label encoded?
  4. What is an advantage of using PC-relative addressing for branches and jumps?
  5. Which statement about instruction length in the RISC-V base ISA and in x86 is correct?