No-op (also spelled as "noop" and "nop") is an abbreviation for "no-operation". It is code that does nothing and has no effect. It is used for filling space (adding padding) and/or wasting time. "nop" is a common instruction in assembly language.
The great art of doing nothing
What is it, and how did it come to be?
No-OPeration (nop
, no-op
) is the proper instruction to instruct a processor to do nothing (but waste time).
Just about every instruction-set has at least some instructions which have no effect at all. They naturally occur because it pays to build a regular IS, which leads to curiosities like exchange A for A, assign A to A, bitwise-and/or A and A.
While some of those may be redefined for better instruction density, one will be chosen as intended nop
.
Purpose/Uses
There are a great many uses for doing nothing. Some examples:
Reserving space for adding patches
Some Windows system binariesreserve space to allow live-patching.
Neutralizing code
An example is an implementation of a seldom changed flag in high-performance-code: Either there's an unconditional jump to additional code, or there's a single, efficient
nop
Aligning code for better caching
If a function begins at the start of a cache-line (or even memory-page), there will often be fewer cache-misses
Wasting time
Counting instructions and busy-Loops for delaying are getting less common in high-end systems, though they are still alive and well on slower machines.
(Attacking) Making a bigger target for a (semi-)blind jump by building a
nop
-slide.