NOP (code)

In computer science, a NOP, no-op, or NOOP (pronounced "no op"; short for no operation) is an assembly language instruction, programming language statement, or computer protocol command that does nothing.
Machine language instructions.
Some computer instruction sets include an instruction whose explicit purpose is to not change the state of any of the programmer-accessible registers, status flags, or memory. It often takes a well-defined number of clock cycles to execute. In other instruction sets, a NOP can be simulated by executing an instruction having operands that cause the same effect; e.g., on the SPARC processor, the instruction codice_1 is the recommended solution.
A NOP is most commonly used for timing purposes, to force memory alignment, to prevent hazards, to occupy a branch delay slot, to render void an existing instruction such as a jump, or as a place-holder to be replaced by active instructions later on in program development (or to replace removed instructions when reorganizing would be problematic or time-consuming). In some cases, a NOP can have minor side effects; for example, on the Motorola 68000 series of processors, the NOP opcode causes a synchronization of the pipeline.
Listed below are the NOP instruction for some CPU architectures:
From a hardware design point of view, unmapped areas of a bus are often designed to return zeroes; since the NOP slide behavior is often desirable, it gives a bias to coding it with the all-zeroes opcode.
Code.
NOP is sometimes used as a description for the action performed by a function or a sequence of programming language statements if the function or code has no effect (it might also be called redundant code). A common compiler optimization is the detection and removal of this kind of code. Such code may be required by the grammar of the programming language, which does not allow a blank.
Ada.
In Ada, the codice_2 statement serves as a NOP. As the syntax forbids that control statements or functions be empty, the codice_2 statement must be used to specify that no action is required. (Thus, if the programmer forgets to write a sequence of statements, the program will fail to compile.)
C and derivatives.
The second line below is an example of a single C statement that "behaves" like a NOP. In practice, most compilers will not generate code for this statement:
 int i = 0;
 i+1;
This statement performs an addition and discards the result. Indeed, any statement without side effects (and that does not affect control flow, e.g., break, return) can be removed, as the result of the computation is discarded.
The simplest possible statement in C that behaves like a NOP is the so-called "null statement", which is just a semi-colon in a context requiring a statement. (A compiler is not required to generate a NOP instruction in this case; typically, no instructions whatsoever would be generated.)
Alternatively, an empty block (compound statement) may be used, and may be more legible:
In some cases, such as the body of a function, a block must be used, but this can be empty. In C, statements cannot be empty—simple statements must end with a ; (semicolon) while compound statements are enclosed in {} (braces), which does not itself need a following semicolon. Thus in contexts where a statement is grammatically required, some such null statement can be used.
The null statement is useless by itself, but it can have a syntactic use in a wider context, e.g., within the context of a loop:
alternatively,
 while (getchar() != '\n')
or more tersely:
 while (getchar() != '\n');
(note that the last form may be confusing, and as such generates a warning with some compilers or compiler options, as semicolon usually indicates an end of function call instruction when placed after a parenthesis on the end of line).
The above code continues calling the function "getchar()" until it returns a \n (newline) character, essentially fast-forwarding the current reading location of standard input to the beginning of next line.
Fortran.
In Fortran, the codice_4 statement is used in some contexts such as the last statement in a DO loop, although it can be used anywhere, and does not have any functionality.
JavaScript.
The JavaScript language does not have a built-in NOP statement. Many implementations are possible:
Alternatives, in situations where a function is required, are:
const noop = () => {};
AngularJS.
The AngularJS framework provides angular.noop function that performs no operations.
jQuery.
The jQuery library provides a function codice_11, which does nothing.
Lodash.
The Lodash library provides a function codice_12, which returns undefined and does nothing.
Pascal.
As with C, the ; used by itself can be used as a null statement in Pascal. In fact, due to the specification of the language, in a BEGIN / END block, the semicolon is optional before the END statement, thus a semicolon used there is superfluous. 
Also, a block consisting of codice_13 may be used as a placeholder to indicate no action, even if placed inside another BEGIN / END block.
Python.
The Python programming language has a codice_14 statement which has no effect when executed and thus serves as a NOP. It is primarily used to ensure correct syntax due to Python's indentation-sensitive syntax; for example the syntax for definition of a class requires an indented block with the class logic, which has to be expressed as codice_14 when it should be empty.
Shell scripting (bash, zsh, etc.).
The 'codice_16' [colon] command is a shell builtin that has similar effect to a "NOP" (a do-nothing operation). It is not technically an NOP, as it changes the special parameter $? (exit status of last command) to 0. It may be considered a synonym for the shell builtin 'true', and its exit status is true (0).
TeX macro language (ConTeXt, LaTeX, etc.).
The TeX typographical system's macro language has the codice_17 command. It does nothing by itself, but may be used to prevent the immediately preceding command from parsing any subsequent tokens.
NOP protocol commands.
Many computer protocols, such as telnet, include a NOP command that a client can issue to request a response from the server without requesting any other actions. Such a command can be used to ensure the connection is still alive or that the server is responsive. A NOOP command is part of the following protocols ("this is a partial list"):
Note that unlike the other protocols listed, the IMAP4 NOOP command has a specific purpose—it allows the server to send any pending notifications to the client.
While most telnet or FTP servers respond to a NOOP command with "OK" or "+OK", some programmers have added quirky responses to the client. For example, the codice_18 daemon of MINIX responds to NOOP with the message:
 200 NOOP to you too!
Cracking.
NOPs are often involved when cracking software that checks for serial numbers, specific hardware or software requirements, presence or absence of hardware dongles, etc. This process is accomplished by altering functions and subroutines to bypass security checks and instead simply return the expected value being checked for. Because most of the instructions in the security check routine will be unused, these would be replaced with NOPs, thus removing the software's security functionality without altering the positioning of everything which follows in the binary.
Security exploits.
The NOP opcode can be used to form a NOP slide, which allows code to execute when the exact value of the instruction pointer is indeterminate (e.g., when a buffer overflow causes a function's return address on the stack to be overwritten).