NOP
is a pseudoinstruction that expands to ADDI x0, x0, 0
. The x0
(or zero
) is a read-only register dedicated to the value zero, i.e., it is hardwired to zero for every single bit. Whatever is written to this register is simply discarded since its value can't be modified.
From The RISC-V Instruction Set Manual Volume I: Unprivileged ISA:
The NOP
instruction does not change any architecturally visible state, except for advancing the pc
and incrementing any applicable performance counters. NOP
is encoded as ADDI x0, x0, 0
.
Keeping in mind that RISC-V has no arithmetic flags (i.e., carry, overflow, zero, sign flags), any arithmetic operation whose destination register is x0
will do as a no operation instruction regardless of the source registers since the net result will consist of advancing the program counter to the next instruction without changing any other relevant processor's state.