ISA & Assembly
Which real instruction does the assembler use for the RISC-V pseudo-instruction "nop" (do nothing)?
- Aaddi x0, x0, 0
- Bjal ra, 0
- 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.