In computer science, a NOP, no-op, or NOOP (pronounced "no op"; short for no operation) is a machine language instruction and its assembly language mnemonic, programming language statement, or computer protocol command that does nothing.

Machine language instructions

Some computer instruction sets include an instruction whose 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, 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, <code>sethi 0, %g0</code>.

A NOP must not access memory, as that could cause a memory fault or page fault.

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, 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.

Listed below are the NOP instruction for some CPU architectures:

{| class="wikitable sticky-header" border="1"

|-

! CPU architecture

! Instruction mnemonic

! Bytes

! Opcode

! Notes

|-

| rowspan=3 | Intel x86 CPU family

| <code>NOP</code>

| 1

| 0x90

| 0x90 is the one-byte encoding for <code>XCHG AX,AX</code> in 16-bit code and <code>XCHG EAX,EAX</code> in 32-bit code. In long mode, <code>XCHG RAX,RAX</code> requires two bytes, as it would begin with an <code>REX.W</code> prefix, making the encoding 0x48 0x90. However, 0x90 is interpreted as a <code>NOP</code> in long mode regardless of whether it is preceded by 0x48.

|-

| <code>FNOP</code>

| 4

| 0xB0000000

| Floating-point no-operation. Opcode for , a shift-right-double instruction that takes the all-0s register as input and output.

|-

| rowspan=5 | Intel IA-64 (Itanium)

| <code>(qp) NOP.b imm21</code>

| 41 bits

| 0x04000000000

| rowspan=5 | On IA-64, the <code>NOP</code> instruction has five forms, each of which can be executed only on a particular execution unit type.

All five <code>NOP</code> forms include a 6-bit qp field (bits 5:0) and a 21-bit immediate field (bit 36 + bits 25:6). These fields may be set to any value with no effect on the operation of the instruction. (The encodings listed here result from setting these fields to all-0s – which is common but not required).

The <code>NOP.x</code> form of the instruction additionally consumes a second 41-bit instruction slot – the contents of this slot is considered to be providing 41 additional immediate-bits, for a total immediate-size of 62 bits.

|-

| <code>(qp) NOP.f imm21</code>

| rowspan=3 | 41 bits

| rowspan=3 | 0x00008000000

|-

| <code>(qp) NOP.i imm21</code>

|-

| <code>(qp) NOP.m imm21</code>

|-

|

| 41+41 bits

| 0x00008000000 imm41

|-

! colspan=5 |

|-

| rowspan=4 | 32-bit ARM (A32)

| <code>NOP</code> || 4 || 0x*320F000

| Architectural ARM A32 NOP ("true" nop, with no register dependencies). Introduced with ARMv6K (ARM 1176, released in 2003), and present in all later ARM A32 processors. (The * indicates a 4-bit field that may take any value other than 0xF.)

|-

| <code>MOV r0,r0</code>/<code>NOP</code> || 4 || 0xE1A00000

| Recommended A32 no-operation encoding for older 32-bit ARM processors that pre-date ARMv6K. Assemblers for A32 will usually output this opcode when given the "NOP" mnemonic unless they are told to target ARMv6K or later versions of the ARM architecture.

|-

| <code>ANDEQ r0,r0,r0</code> || 4 || 0x00000000

| Bitwise-AND r0 with itself if equal. Commonly used no-op encoding due to the simplicity of its encoding.

|-

| <code>MOVNV r0,r0</code> || 4 || 0xF1A00000

| Move r0 to itself never. Obsolete no-op encoding that used to be recommended for the ARM2/ARM3 processors in older Acorn Archimedes computers. Makes use of the NV ("never") condition code – which has been deprecated since 1993, with support fully removed with ARMv5.

|-

| Thumb

| <code>MOV r8,r8</code>/<code>NOP</code> || 2 || 0x46C0

| Recommended Thumb no-operation encoding for older 32-bit Thumb processors that pre-date ARMv6T2. Assemblers for T32 will usually output this opcode when given the "NOP" mnemonic unless they are told to target ARMv6T2 or later versions of the ARM Thumb architecture.

|-

| <code>FNOP</code>

| 4

| 0x5FFF041F

| Floating-point NOP. Opcode for <code>CPYS f31,f31,f31</code>, an instruction that performs copy-sign with the always-0 register as source for both sign and exponent/mantissa, and stores the result in the always-0 register. The address register and displacement may take any value, but is most commonly given as <code>0($sp)</code> which is stack pointer + zero.

|-

| AMD 29k

| <code>NOP</code>

| 4

| 0x70400101

| Opcode for <code>aseq 0x40,gr1,gr1</code>, an instruction that asserts that the stack register is equal to itself.

|-

| AVR

| <code>NOP</code>

| 2

| 0x0000

| one clock cycle

|-

| COP400

| <code>NOP</code>

| 1

| 0x44

|

|-

| COP8

| <code>NOP</code>

| 1

| 0xB8

|

|-

| HP 3000

| <code>NOP</code>

| 2

| 0x0000

| HP 3000 stack operation instructions have most-significant four bits of 0 followed by two 6-bit stack opcodes, with stack NOP (0) used to pad when needed. 0x0000 would be NOP, NOP.

|-

| Hyperstone E1

| <code>NOP</code>

| 2

| 0x0300

| Opcode for <code>CHK L0,L0</code>, a range-check instruction which produces an exception if the L0 register is greater than itself.

|-

| rowspan=2 |

| <code>NOP</code>

| 4

| 0x47000000 or 0x470nnnnn or 0x47n0nnnn where "n" is any 4-bit value.

|rowspan=2| The NOP ("No-Op") and NOPR ("No-Op Register") are a subset of the "Branch on Condition" or "Branch on Condition Register" instructions, respectively; both versions have two options for generating a NO-OP.

In the case of both the NOP and NOPR instructions, the first 0 in the second byte is the "mask" value, the condition to test such as equal, not equal, high, low, etc. If the mask is 0, no branch occurs.

In the case of the NOPR instruction, the second value in the second byte is the register to branch on. If register 0 is chosen, no branch occurs regardless of the mask value. Thus, if either of the two values in the second byte is 0, the branch will not happen. If the first 0 in the second byte is 0, the value of the second value in the second byte is irrelevant on most processors; however, on the IBM System/360 Model 91, if that value refers to register 15, the instruction will wait for all previously-decoded instructions to complete before continuing.

In the case of the NOP instruction, the second value in the second byte is the "base" register of a combined base register, displacement register and offset address. If the base register is also 0, the branch is not taken regardless of the value of the displacement register or displacement address.

|-

| <code>NOPR</code>

| 2

| 0x0700 or 0x070n or 0x07n0 where "n" is any 4-bit value.

|-

| LoongArch

| <code>NOP</code>

| 4

| 0x03400000

| Opcode for <code>andi r0,r0,0</code>, an instruction that bitwise-ANDs the always-0 register with zero.

|-

| MicroBlaze

| <code>NOP</code>

| 4

| 0x80000000

| Opcode for <code>or r0,r0,r0</code>, an instruction that bitwise-ORs the always-0 register with itself.

|-

| MIPS

| <code>NOP</code>

| 4

| 0x00000000

| Stands for <code>sll r0,r0,0</code>, meaning: Logically shift register 0 zero bits to the left and store the result in register 0. Writes to register 0 are ignored; it always contains 0.

|-

| MIPS-X

| <code>NOP</code>

| 4

| 0x60000019

| (extended opcode for <code>add r0,r0,r0</code>)

|-

| MIX

| <code>NOP</code>

| 1 word

| ± * * * * 0

| The * bytes are arbitrary, and can be anything from 0 to the maximum byte (required to be in the range 63-99). MIX uses sign-magnitude representation.

|-

| MMIX

| <code>SWYM</code>

| 4

| 0xFD******

| SWYM stands for "Sympathize with your machinery". The * digits can be chosen arbitrarily.

|-

| MOS Technology 65xx (e.g. 6502),<br/>WDC 65C816

| <code>NOP</code>

| 1

| 0xEA

| NOP consumes two clock cycles. Undefined opcodes in the NMOS versions of the 65xx family were converted to be NOPs of varying instruction lengths and cycle times in the 65C02.

|-

| Motorola 6800

| <code>NOP</code>

| 1

| 0x01

|

|-

| rowspan=2 | Motorola 68000 family

| <code>NOP</code>

| 2

| 0x4E71

| This synchronizes the pipeline and prevents instruction overlap.

|-

| <code>TRAPF</code>,<br/><br/><code>TRAPF.L #data</code>

| 2,<br/>4,<br/>6

| 0x51FC,<br/><br/>

| Trap if false.

Suggested opcode for 68020 and later 68k processors if a NOP without pipeline synchronization is desired. ('n' may take any 4-bit value.)

|-

| Motorola 6809

| <code>NOP</code>

| 1

| 0x12

|

|-

| Motorola 88000 family

| <code>BCND lt0,r0,X</code>,<br/><code>ADD r0,r0,r0</code>,<br/><code>TB1 0,r0,x</code>

| 4

| 0xE980xxxx,<br/>0xF4007000,<br/>0xF000D8xx

| Branch if always-0 register is less than 0,<br/>Add always-0 register to itself,<br/>Trap if bit 0 of always-0 register is 1 (serializing).

|-

| MSP430

| <code>NOP</code>

| 2

| 0x4303

| Opcode for <code>mov #0,r3</code> or <code>mov r3,r3</code>, an instruction that performs a move from a "constant generation register" to itself.

|-

| rowspan=2 | PA-RISC

| <code>NOP</code>

| 4

| 0x08000240

| Opcode for <code>OR 0,0,0</code>.

|-

| PDP-6, PDP-10

| <code>JFCL 0,</code> (conventional)<br><code>JUMP, SETA, SETAI, CAI, TRN, TLN</code>

| 1 word

| 25500******* (octal)

| Jump never<br>Jump never, set nothing, skip never

|-

| PDP-11

| <code>NOP</code>

| 2

| 000240 (octal)

| Clear none of the condition codes

|-

| PIC microcontroller

| <code>NOP</code>

| 12 bits

| 0b000000000000

| Number of bits in NOP varies by series.

|-

| POWER, PowerPC, Power ISA

| <code>NOP</code>

| 4

| 0x60000000

| Opcode for <code>ori r0,r0,0</code>.

Under the Power ISA, many apparent no-op instruction encodings have significant side-effects – therefore, no-op encodings other than should be carefully avoided unless these side-effects are specifically intended. For example:

  • <code>ori r31,r31,0</code> is a serializing instruction.
  • <code>or rX,rX,rX</code> with X=1,2,3,5,6,7 or 31 sets thread priority based on X.
  • <code>or r26,r26,r26</code> is a memory store writeback hint.
  • <code>xori r0,r0,0</code> is an explicitly unoptimized no-op for use in timing-loops.
  • <code>and rX,rX,rX</code> with X=0,1 are performance-probe no-ops.
  • <code>or rX,rX,rX</code> with X=28,29,30,31 will stall instruction dispatch for a fixed number of CPU cycles on IBM PPE based processors.
  • <code> ori rX,rX,0</code> with X=1,2 are "group ending NOP"s in some POWER CPUs

|-

| rowspan=2 | RISC-V

| <code>NOP</code>

| 4

| 0x00000013

| <code>ADDI x0, x0, 0</code>

|-

| <code>C.NOP</code>

| 2

| 0x0001

| <code>C.ADDI x0, 0</code>. Only available on RISC-V CPUs that support the "C" (compressed instructions) extension.

|-

| Signetics 8X300

| <code>MOV AUX, AUX</code>

| 2 <small>(16 bits)</small>

| 0x0000

| Move AUX to AUX with no rotate

|-

| SPARC

| <code>NOP</code>

| 4

| 0x01000000

| Stands for <code>sethi 0, %g0</code> which zeroes the hardwired-to-zero <code>%g0</code> register

|-

| rowspan=2 | Sunplus S+core

| <code>NOP</code>

| 4

| 0x80008000

| rowspan=2 | Architectural NOPs

|-

| <code>NOP!</code>

| 2

| 0x0000

|-

| rowspan=2 | SuperH

| <code>NOP</code>

| 2

| 0x0009

|

|-

| <code>NOP</code>

| 4

| 0x6FF0FFF0

| 32-bit NOP, present on SH-5 only.

|-

| rowspan=2 | Tensilica Xtensa

| <code>NOP</code>, <code>_NOP</code>

| 3

| 0x0020F0

| rowspan=2 | Assemblers may convert "NOP" to "NOP.N" – the "_NOP" mnemonic (with a leading underscore) can be used to prevent such conversion.

|-

| <code>NOP.N</code>

| 2

| 0xF03D

|-

| VAX

| <code>NOP</code>

| 1

| 0x01

| Delay is dependent on processor type.

|-

| WD16

| <code>NOP</code>

| 2

| 0x0000

|

|}

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

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, the <code>null</code> statement serves as a NOP. As the syntax forbids that control statements or functions be empty, the <code>null</code> 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.

Most C compilers generate no code for null statements, which has historical and performance reasons.

;

An empty block (compound statement) is also a NOP, and may be more legible, but will still have no code generated for it by the compiler.

{}

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 <code>;</code> (semicolon) while compound statements are enclosed in <code>{}</code> (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:

<syntaxhighlight lang="c">

while (getchar() != '\n') {}

</syntaxhighlight>

alternatively,

<syntaxhighlight lang="c">

while (getchar() != '\n')

;

</syntaxhighlight>

or more tersely:

<syntaxhighlight lang="c">

while (getchar() != '\n');

</syntaxhighlight>

The last form might generate a warning with some compilers or compiler options, as a semicolon placed after a parenthesis at the end of a line usually indicates the end of a function call expression.

The above code continues calling the function <code>getchar()</code> until it returns a <code>\n</code> (newline) character, essentially fast-forwarding the current reading location of standard input to the beginning of next line.

Fortran

In Fortran, the <code>CONTINUE</code> 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:

  • Use the <code>;</code> empty statement or the <code>{}</code> empty block statement the same way as in the C and derivatives examples;
  • Use the <code>undefined</code> or the <code>null</code> 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 <code>Function.prototype()</code> built-in function, that accepts any arguments and returns <code>undefined</code>;
  • 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 arrow function syntax):

<syntaxhighlight lang="javascript">const noop = () => {};</syntaxhighlight>

AngularJS

The AngularJS framework provides angular.noop function that performs no operations.

jQuery

The jQuery library provides a function <code>jQuery.noop()</code>, which does nothing.

Lodash

The Lodash library provides a function <code>_.noop()</code>, 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 <code> BEGIN END;</code> 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 <code>pass</code> 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 <code>pass</code> when it should be empty.

Shell scripting (bash, zsh, etc.)

The '<code>:</code>' [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 <code>\relax</code> 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):

  • telnet
  • FTP
  • SMTP
  • X11
  • POP3
  • NNTP
  • finger
  • IMAP4
  • BitTorrent

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 <code>ftpd</code> 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. in the form of a NOP slide. 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).

See also

  • Comment (computer programming) – annotations generally for programmers that are ignored by compilers and interpreters
  • Computer architecture
  • Filler text
  • Halt and Catch Fire – also pauses the CPU
  • HLT (x86 instruction) – pauses the CPU
  • Identity function – the functional programming equivalent to NOP
  • IEFBR14 – mainframe tautology
  • xyzzy (computing) – a command sometimes used instead of NOP
  • X86 instruction listings#Added in P5/P6-class processors – <code>NOPL</code>, the official long <code>NOP</code>

References