Questions tagged [no-op]

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 has at least some s 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.

References

115 questions
15
votes
2 answers

Why does gcc output machine code have nop instructions

Everytime I do an objdump -d I always see the asm code with batches of nop instructions (instructions that do nothing) For example take this same program: #include #include int main() { printf("Hello World!\n"); …
PuercoPop
  • 6,707
  • 4
  • 30
  • 40
15
votes
2 answers

Why does x86 nopl instruction take an operand?

Why does a nopl instruction in an x86 take an operand? Don't nops just do, well, nothing? nopl 0x0(%rax)
RouteMapper
  • 2,484
  • 1
  • 26
  • 45
14
votes
1 answer

how to to do the "noop but return unit" in OCaml

I want to print a list of strings after going through a pattern matching just to get into this powerful functionality. How can I express the "do-nothing-but-return-unit" operation ? What I mean is: let print_nodes nodes = match nodes with …
Jack
  • 131,802
  • 30
  • 241
  • 343
13
votes
3 answers

What would be a good noop for PhP

Sometimes I do not want to do anything. I just want to have a statement so I can put break point. In c and objective-c we have while (false); Say I want to break a function -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; …
user4234
  • 1,523
  • 1
  • 20
  • 37
10
votes
1 answer

Why does GCC on x86-64 insert a NOP inside of a function?

Given the following C function: void go(char *data) { char name[64]; strcpy(name, data); } GCC 5 and 6 on x86-64 compile (plain gcc -c -g -o followed by objdump) this to: 0000000000000000 : 0: 55 push %rbp …
Thomas Luzat
  • 710
  • 7
  • 21
10
votes
3 answers

Equivalent for NOP in C for Embedded?

I use KEIL to compile a program. The program uses the code asm("NOP"); Unfortunately KEIL compiler does not accept the statement. The idea is to introduce a delay by using NOP (no operation) assembly code. What is the actual equivalent of this in…
AAI
  • 290
  • 1
  • 3
  • 20
9
votes
1 answer

Why was NOP assigned to 0x90 in x86 assembly?

Why was nop assigned to 0x90 on intel x86 assembly? Intuitively I would expect that 0x00 would map to nop (which is also xchg eax, eax at intel x86) as it is the case for ARM A32 and some other architectures.
Jonas Stein
  • 6,826
  • 7
  • 40
  • 72
9
votes
4 answers

Is there an angular.noop for Angular 6?

In my Angular 6 application, I need a function that does nothing. Obviously, I could just write my own, but I was reading about angular.noop which I would like to use. However, I get an angular.noop is not a function error when I try to use it. I…
Stack Underflow
  • 2,363
  • 2
  • 26
  • 51
9
votes
3 answers

RISC-V NOP instruction

I am working on RISC-V 32I instructions recently. I got a question about NOP instruction, which the specification says it is equal to ADDI x0, x0, 0. However, x0 is not a general register which can be modified by the programmer. Thus, why x0 serves…
Betty
  • 161
  • 1
  • 2
  • 6
9
votes
1 answer

What does $_SERVER on its own do?

I have come across the following three lines of code: $_SERVER; $_ENV; $_REQUEST; To me it seems like these three lines of code do nothing. They don't cause any errors. I know what these three global variables are, I just don't know what these…
Graham
  • 7,807
  • 20
  • 69
  • 114
8
votes
1 answer

Why does MSVC generate nop instructions for atomic loads on x64?

If you compile code such as #include int load(std::atomic *p) { return p->load(std::memory_order_acquire) + p->load(std::memory_order_acquire); } you see that MSVC generates NOP padding after each memory load: int…
user541686
  • 205,094
  • 128
  • 528
  • 886
8
votes
3 answers

How many 1-byte NOPs can Skylake execute at one cycle

I'm aligning branch targets with NOPs, and sometimes the CPU executes these NOPs, up to 15 NOPs. How many 1-byte NOPs can Skylake execute in one cycle? What about other Intel-compatible processors, like AMD? I'm interested not only in Skylake but in…
Maxim Masiutin
  • 3,991
  • 4
  • 55
  • 72
8
votes
4 answers

Processor Instruction Cycle Execution Time

My guess is that the __no_operation() intrinsic (ARM) instruction should take 1/(168 MHz) to execute, provided that each NOP executes in one clock cycle, which I would like to verify via documentation. Is there a standard location for…
bunkerdive
  • 2,031
  • 1
  • 25
  • 28
7
votes
1 answer

Is a 'noop' [lodash] default parameter required for function props?

I was wondering what people suggest when working with optional default functions in React. I have seen our codebase use a mix of () => {} and the lodash noop. Which is preferable? This is a general question regarding proper coding…
ParthianShotgun
  • 602
  • 4
  • 20
7
votes
1 answer

What's the purpose of `qt_noop`

I just found the existence of qt_noop() define in the qglobal.h as: inline void qt_noop() {} What's the point of it?
gregseth
  • 12,952
  • 15
  • 63
  • 96