In
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to practical disciplines (includi ...
, a NOP, no-op, or NOOP (pronounced "no op"; short for no operation) is a
machine language
In computer programming, machine code is any low-level programming language, consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). Each instruction causes the CPU to perform a very ...
instruction and its
assembly language mnemonic,
programming language
A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language.
The description of a programming ...
statement, or
computer protocol
A communication protocol is a system of rules that allows two or more entities of a communications system to transmit information via any kind of variation of a physical quantity. The protocol defines the rules, syntax, semantics and synchroniza ...
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
Memory is the faculty of the mind by which data or information is encoded, stored, and retrieved when needed. It is the retention of information over time for the purpose of influencing future action. If past events could not be remembered ...
. It often takes a well-defined number of
clock cycles
In electronics and especially synchronous digital circuits, a clock signal (historically also known as ''logic beat'') oscillates between a high and a low state and is used like a metronome to coordinate actions of digital circuits.
A clock signa ...
to execute. In other instruction sets, there is no explicit NOP instruction, but the assembly language mnemonic NOP represents an instruction which acts as a NOP; e.g., on the
SPARC
SPARC (Scalable Processor Architecture) is a reduced instruction set computer (RISC) instruction set architecture originally developed by Sun Microsystems. Its design was strongly influenced by the experimental Berkeley RISC system develope ...
,
sethi 0, %g0
.
A NOP must not access memory, as that could cause a
memory fault
A general protection fault (GPF) in the x86 instruction set architectures (ISAs) is a fault (a type of interrupt) initiated by ISA-defined protection mechanisms in response to an access violation caused by some running code, either in the kernel ...
or
page fault
In computing, a page fault (sometimes called PF or hard fault) is an exception that the memory management unit (MMU) raises when a process accesses a memory page without proper preparations. Accessing the page requires a mapping to be added t ...
.
A NOP is most commonly used for timing purposes, to force
memory alignment, to prevent
hazards, to occupy a
branch delay slot
In computer architecture, a delay slot is an instruction slot being executed without the effects of a preceding instruction. The most common form is a single arbitrary instruction located immediately after a branch instruction on a RISC or DSP ...
, to render void an existing instruction such as a jump, as a target of an
execute instruction, 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
Pipeline may refer to:
Electronics, computers and computing
* Pipeline (computing), a chain of data-processing stages or a CPU optimization found on
** Instruction pipelining, a technique for implementing instruction-level parallelism within a s ...
.
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
In computer security, a NOP slide, NOP sled or NOP ramp is a sequence of NOP (no-operation) instructions meant to "slide" the CPU's instruction execution flow to its final, desired destination whenever the program branches to a memory address a ...
behavior is often desirable, it gives a bias to coding it with the all-zeroes opcode.
Code
A function or a sequence of programming language statements is a NOP or null statement if it has no effect. Null statements may be required by the
syntax of some languages in certain contexts.
Ada
In
Ada
Ada may refer to:
Places
Africa
* Ada Foah, a town in Ghana
* Ada (Ghana parliament constituency)
* Ada, Osun, a town in Nigeria
Asia
* Ada, Urmia, a village in West Azerbaijan Province, Iran
* Ada, Karaman, a village in Karaman Province, ...
, the
null
statement serves as a NOP. As the syntax forbids that control statements or functions be empty, the
null
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 simplest NOP statement in C is the ''null statement'', which is just a semi-colon in a context requiring a statement.
;
An empty block (compound statement) is also a NOP, 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:
while (getchar() != '\n')
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
CONTINUE
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
JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, of ...
language does not have a built-in NOP statement. Many implementations are possible:
* Use the
;
''empty statement'' or the
empty ''block statement'' the same way as in the
C and derivatives examples;
* Use the
undefined
or the
null
expression as a complete statement (an ''expression statement'') when the previous methods are not allowed by the syntax.
Alternatives, in situations where a function is required, are:
* Use the
Function.prototype()
built-in function, that accepts any arguments and returns
undefined
;
* Use a NOP function available in a third-party library —see below;
* Define a custom NOP function, as in the following example (using the
ES6
ECMAScript (; ES) is a JavaScript standard intended to ensure the interoperability of web pages across different browsers. It is standardized by Ecma International in the documenECMA-262
ECMAScript is commonly used for client-side scripting o ...
arrow function syntax):
const noop = () => ;
AngularJS
The
AngularJS framework provide
angular.noopfunction that performs no operations.
jQuery
The
jQuery
jQuery is a JavaScript library designed to simplify HTML DOM tree traversal and manipulation, as well as event handling, CSS animation, and Ajax. It is free, open-source software using the permissive MIT License. As of Aug 2022, jQuery is u ...
library provides a function
jQuery.noop()
, which does nothing.
Lodash
The
Lodash
Lodash is a JavaScript library which provides utility functions for common programming tasks using the functional programming paradigm.
History
''See also Underscore § History.''
Lodash is a fork of Underscore.js.
It joined the Dojo Fou ...
library provides a function
_.noop()
, 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
BEGIN END;
may be used as a placeholder to indicate no action, even if placed inside another BEGIN / END block.
Python
The
Python
Python may refer to:
Snakes
* Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia
** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia
* Python (mythology), a mythical serpent
Computing
* Python (pro ...
programming language has a
pass
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
Class or The Class may refer to:
Common uses not otherwise categorized
* Class (biology), a taxonomic rank
* Class (knowledge representation), a collection of individuals or objects
* Class (philosophy), an analytical concept used differentl ...
requires an indented block with the class logic, which has to be expressed as
pass
when it should be empty.
Shell scripting (bash, zsh, etc.)
The '
:
'
oloncommand 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
Tex may refer to:
People and fictional characters
* Tex (nickname), a list of people and fictional characters with the nickname
* Joe Tex (1933–1982), stage name of American soul singer Joseph Arrington Jr.
Entertainment
* ''Tex'', the Italian ...
typographical system's macro language has the
\relax
command. It does nothing by itself, but may be used to prevent the immediately preceding command from parsing any subsequent tokens.
[TeX wikibook â€]
relax
/ref>
NOP protocol commands
Many computer protocol
A communication protocol is a system of rules that allows two or more entities of a communications system to transmit information via any kind of variation of a physical quantity. The protocol defines the rules, syntax, semantics and synchroniza ...
s, such as telnet
Telnet is an application protocol used on the Internet or local area network to provide a bidirectional interactive text-oriented communication facility using a virtual terminal connection. User data is interspersed in-band with Telnet contr ...
, 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''):
* telnet
Telnet is an application protocol used on the Internet or local area network to provide a bidirectional interactive text-oriented communication facility using a virtual terminal connection. User data is interspersed in-band with Telnet contr ...
* FTP
The File Transfer Protocol (FTP) is a standard communication protocol used for the transfer of computer files from a server to a client on a computer network. FTP is built on a client–server model architecture using separate control and data ...
* SMTP
The Simple Mail Transfer Protocol (SMTP) is an Internet standard communication protocol for electronic mail transmission. Mail servers and other message transfer agents use SMTP to send and receive mail messages. User-level email clients ty ...
* X11
The X Window System (X11, or simply X) is a windowing system for bitmap displays, common on Unix-like operating systems.
X provides the basic framework for a GUI environment: drawing and moving windows on the display device and interacting wi ...
* POP3
In computing, the Post Office Protocol (POP) is an application-layer Internet standard protocol used by e-mail clients to retrieve e-mail from a mail server. POP version 3 (POP3) is the version in common use, and along with IMAP the most common ...
* NNTP
The Network News Transfer Protocol (NNTP) is an application protocol used for transporting Usenet news articles (''netnews'') between news servers, and for reading/posting articles by the end user client applications. Brian Kantor of the Univers ...
* finger
A finger is a limb of the body and a type of digit, an organ of manipulation and sensation found in the hands of most of the Tetrapods, so also with humans and other primates. Most land vertebrates have five fingers ( Pentadactyly). Chambers ...
* IMAP4
In computing, the Internet Message Access Protocol (IMAP) is an Internet standard protocol used by email clients to retrieve email messages from a mail server over a TCP/IP connection. IMAP is defined by .
IMAP was designed with the goal of per ...
* BitTorrent
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
Telnet is an application protocol used on the Internet or local area network to provide a bidirectional interactive text-oriented communication facility using a virtual terminal connection. User data is interspersed in-band with Telnet contr ...
or FTP
The File Transfer Protocol (FTP) is a standard communication protocol used for the transfer of computer files from a server to a client on a computer network. FTP is built on a client–server model architecture using separate control and data ...
servers respond to a NOOP command with "OK" or "+OK", some programmers have added quirky responses to the client. For example, the ftpd
daemon of MINIX responds to NOOP with the message:
200
__NOTOC__
Year 200 ( CC) was a leap year starting on Tuesday (link will display the full calendar) of the Julian calendar. At the time, it was known as the Year of the Consulship of Severus and Victorinus (or, less frequently, year 953 ''Ab ur ...
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
In computer security, a NOP slide, NOP sled or NOP ramp is a sequence of NOP (no-operation) instructions meant to "slide" the CPU's instruction execution flow to its final, desired destination whenever the program branches to a memory address a ...
, 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).
See also
* Computer architecture
In computer engineering, computer architecture is a description of the structure of a computer system made from component parts. It can sometimes be a high-level description that ignores details of the implementation. At a more detailed level, the ...
* HLT (x86 instruction)
In the x86 computer architecture, HLT (halt) is an assembly language instruction which halts the central processing unit (CPU) until the next external interrupt is fired. Interrupts are signals sent by hardware devices to the CPU alerting it that ...
– pauses the CPU
* Halt and Catch Fire – also pauses the CPU
* Identity function
Graph of the identity function on the real numbers
In mathematics, an identity function, also called an identity relation, identity map or identity transformation, is a function that always returns the value that was used as its argument, un ...
– the functional programming equivalent to NOP
* xyzzy (computing)
In computing, Xyzzy is sometimes used as a metasyntactic variable or as a video game cheat code. ''Xyzzy'' comes from the ''Colossal Cave Adventure'' computer game, where it is the first "magic word" that most players encounter (others include "p ...
– a command sometimes used instead of NOP
* IEFBR14 – mainframe tautology
* Filler text
Filler text (also placeholder text or dummy text) is text that shares some characteristics of a real written text, but is random or otherwise generated. It may be used to display a sample of fonts, generate text for testing, or to spoof an e ...
* Comment (computer programming) – annotations generally for programmers that are ignored by compilers and interpreters
References
{{DEFAULTSORT:Nop
Machine code
Computing acronyms
X86 instructions