NOP

By Vesper Vei
2 minutes read

Table of Contents

  1. NOP (nop)
    1. Basic function
    2. Instruction execution process
    3. Instruction format
    4. Behavioral characteristics
    5. Common uses

NOP (nop)

Basic function

The NOP (No Operation) instruction represents a null operation, meaning that after executing this instruction, the processor does not modify any registers, does not access memory, does not change EFLAGS, and does not affect the program’s logical flow. Its only effect is to consume one CPU instruction cycle, allowing the program to continue executing the next instruction sequentially.

Instruction execution process

The internal behavior of NOP can be understood as:

; 执行后 CPU 状态不变

At the microarchitectural level, it is typically implemented as a special marker used for instruction pipeline filling or alignment, and does not produce any actual read or write operations.

Instruction format

The NOP instruction has only one form:

nop

However, in assemblers, multi-byte NOPs can also be used for instruction alignment, for example:

nop
nop DWORD ptr [rax+rax]

These multi-byte NOPs generated by the compiler serve the same purpose: filling space and aligning addresses.

Behavioral characteristics

Equivalent instruction analysis

From a logical perspective, the effect of NOP is equivalent to:

mov eax, eax

That is, performing a self-assignment on a register, but a real NOP does not actually read or write any register, so it is more lightweight.

Assembly optimizers may also simulate NOP with other pseudo-instructions that never change state, for example:

lea rax, [rax]

However, none of these alternative forms is as pure as the native nop.

Common uses



Relationship Graph

Loading graph...