ISA & Assembly

Which real instruction does the assembler use for the RISC-V pseudo-instruction "nop" (do nothing)?

  1. Aaddi x0, x0, 0
  2. Bjal ra, 0
  3. Clw x0, 0(sp)
Show answer and explanation

Answer: A. addi x0, x0, 0

RISC-V has no dedicated do-nothing instruction; nop is encoded as "addi x0, x0, 0". The write to x0 is discarded, so no register or memory changes. Likewise "mv rd, rs" is "addi rd, rs, 0", "j label" is "jal x0, label" and "ret" is "jalr x0, 0(ra)". Using x0 to keep the number of instruction kinds small is part of the RISC-V design philosophy.

  • A. Correct. An add whose result is discarded into x0.
  • B. It overwrites ra, so it is not a no-op.
  • C. It reads memory and could even raise an exception.
Practice this topic Back to topic

More ISA & Assembly questions

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