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
7
votes
1 answer

x86 multi-byte NOP and instruction prefix

As a small recall, the x86 architecture defines 0x0F 0x1F [mod R/M] as a multi-byte NOP. Now I'm looking at the specific case of an 8-byte NOP: I have got 0x0F 0x1F 0x84 0x__ 0x__ 0x__ 0x__ 0x__ where the last 5 bytes have got arbitrary values. The…
ayekat
  • 333
  • 4
  • 9
7
votes
2 answers

Seeking Sqlite no-op command

Is there a command which I can run to do nothing (or very little) which will never error? I need something for testing porpoises.
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
7
votes
1 answer

"No operation" haskell

If I remember correctly from school, there's a function or keyword that is used for "not yet implemented" but the code compiles. I've tried to search for it, but can't find. Any one know what I'm looking for? is's something like isDivisor :: Integer…
Viktor Mellgren
  • 4,318
  • 3
  • 42
  • 75
7
votes
5 answers

Is there some no op operation in objective-c that we can use just to set breakpoint

The code shouldn't have any effect It should be doable anywhere It doesn't generate compiler warning Basically sometimes I want to do NSAssert. However, rather than NSAssert, I sometimes want to do my if {} my self. That way I can just easily set…
user4951
  • 32,206
  • 53
  • 172
  • 282
6
votes
1 answer

Cmd with no message in Elm

Is it possible to create a Cmd that sends no message on completion in Elm? Specifically, I am trying to have an element grab the focus (programmically), but I don't need to be informed of the result: Dom.focus "element-id" |> Task.attempt…
Ralph
  • 31,584
  • 38
  • 145
  • 282
6
votes
2 answers

Can my CPU execute multiple NOPs per CPU cycle?

I wrote a simple program that executes a bunch of NOP instructions in a loop, and to my surprise it executes about 10600000000 of them per second, or about 10Ghz, while my CPU is only 2.2GHz. How is this possible? Is the CPU treating them as a…
Pepijn
  • 4,145
  • 5
  • 36
  • 64
6
votes
3 answers

Python NOOP replacement

Often I need to temporary comment some code, but there are situations like the following where commenting a single line of code will get a syntax error if state == False: print "Here I'm not good do stuff" else: # print "I am good here but…
Eduard Florinescu
  • 16,747
  • 28
  • 113
  • 179
6
votes
2 answers

Does a typedef to self have any effect?

I've come across some C++ code that has the following: typedef Request Request; Is this just a no-op or does this typedef actual have an effect, and if so, what effect does it have?
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
5
votes
2 answers

Why is assert defined as (void)0?

Why #define assert(expression) ((void)0), rather than #define assert(expression) is used in release mode?(strictly speaking, when NDEBUG is defined) I heard that there are some reasons, but I've forgot it.
5
votes
2 answers

Pipe that does nothing

I'm on a AIX box and need a program that when used after a pipe does nothing. I'll be more exact. I need something like this: if [ $NOSORT ] ; then SORTEXEC="/usr/bin/doesnothing" else SORTEXEC="/usr/bin/sort -u" fi # BIG WHILE HERE do done…
5
votes
2 answers

Calculating addresses in NOP sleds

I am currently reading Introduction to computer systems : a programmer's perspective…
user720694
  • 2,035
  • 6
  • 35
  • 57
5
votes
2 answers

No operation command

With Bash, you have the command : Null command. No effect; the command does nothing. Exit Status: Always succeeds. Example : 'foo' Does PowerShell have something similar to this?
Zombo
  • 1
  • 62
  • 391
  • 407
5
votes
5 answers

What do you think of Google's new programming language: Noop?

http://code.google.com/p/noop/ Noop (pronounced noh-awp, like the machine instruction) is a new language that attempts to blend the best lessons of languages old and new, while syntactically encouraging industry best-practices and discouraging the…
Joel Martinez
  • 46,929
  • 26
  • 130
  • 185
4
votes
2 answers

Why use (void)1 as a no-op in C++?

I'm reviewing a third party codebase and see this definition of an assert macro: #define assert( x ) \ if( !( x ) ) { \ ThrowException( __FILE__, __LINE__ ); \ } else \ ((void)1) What's the point in (void)1? How is it…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
4
votes
7 answers

How do you write a no-op statement?

What is the best way to write a no-op statement in Delphi? Take this code: if a=b then SomeOldStatement else AnotherStatement; And say that you temporarily want to rem out SomeOldStatement. Would you just go for this solution: if a=b then …
Jørn E. Angeltveit
  • 3,029
  • 3
  • 22
  • 53