NOP
Encyclopedia
In computer science
Computer science
Computer science or computing science is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems...

, NOP or NOOP (short for No Operation or No Operation Performed) is an assembly language
Assembly language
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...

 instruction, sequence of programming language statements, or computer protocol command that effectively does nothing at all.

NOP machine instruction

Some computer instruction set
Instruction set
An instruction set, or instruction set architecture , is the part of the computer architecture related to programming, including the native data types, instructions, registers, addressing modes, memory architecture, interrupt and exception handling, and external I/O...

s include an instruction whose explicit purpose is not to change the state of any of the programmer accessible registers
Processor register
In computer architecture, a processor register is a small amount of storage available as part of a CPU or other digital processor. Such registers are addressed by mechanisms other than main memory and can be accessed more quickly...

, status flags
Process states
In a multitasking computer system, processes may occupy a variety of states. These distinct states may not actually be recognized as such by the operating system kernel, however they are a useful abstraction for the understanding of processes....

, or memory and which may require a specific number of clock cycles to execute. In other instruction sets, a NOP has to be simulated by executing an instruction having operands that cause the same effect (e.g., on the SPARC
SPARC
SPARC is a RISC instruction set architecture developed by Sun Microsystems and introduced in mid-1987....

 processor, the instruction sethi 0, %g0 is the recommended solution).

A NOP is most commonly used for timing purposes, to force memory alignment
Data structure alignment
Data structure alignment is the way data is arranged and accessed in computer memory. It consists of two separate but related issues: data alignment and data structure padding. When a modern computer reads from or writes to a memory address, it will do this in word sized chunks...

, to prevent hazard
Hazard (computer architecture)
Hazards are problems with the instruction pipeline in central processing unit microarchitectures that potentially result in incorrect computation...

s, to occupy a branch delay slot
Branch delay slot
In computer architecture, a delay slot is an instruction slot that gets 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 architecture; this instruction will execute even if...

, or as a place-holder to be replaced by active instructions later on in program development (or to replace removed instructions when refactoring would be problematic or time-consuming). In some cases, a NOP can have minor side effects; for example, on the Motorola 68000
Motorola 68000
The Motorola 68000 is a 16/32-bit CISC microprocessor core designed and marketed by Freescale Semiconductor...

 series of processors, the NOP opcode will cause a synchronization of the pipeline.

Here are the characteristics of the NOP instruction for some CPU architectures:
CPU architecture Mnemonic
Mnemonic
A mnemonic , or mnemonic device, is any learning technique that aids memory. To improve long term memory, mnemonic systems are used to make memorization easier. Commonly encountered mnemonics are often verbal, such as a very short poem or a special word used to help a person remember something,...

Byte
Byte
The byte is a unit of digital information in computing and telecommunications that most commonly consists of eight bits. Historically, a byte was the number of bits used to encode a single character of text in a computer and for this reason it is the basic addressable element in many computer...

s
Opcode
Opcode
In computer science engineering, an opcode is the portion of a machine language instruction that specifies the operation to be performed. Their specification and format are laid out in the instruction set architecture of the processor in question...

Notes
Intel x86 CPU
Central processing unit
The central processing unit is the portion of a computer system that carries out the instructions of a computer program, to perform the basic arithmetical, logical, and input/output operations of the system. The CPU plays a role somewhat analogous to the brain in the computer. The term has been in...

 family
NOP 1; 1–9 for i686 0x
Hexadecimal
In mathematics and computer science, hexadecimal is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen...

90; 0x0f 0x1f
The NOP instruction on the x86 CPU family is actually XCHG EAX, EAX (resulting the same opcode 0x90) - the instruction without any effect.
Intel 8051 / MCS-51 family NOP 1 0x00
ARM
ARM
An arm is an upper limb of the body.Arm may also refer to:-Geography:* Arm , a narrow stretch of a larger body of water** Canal arm, a subsidiary branch of a canal or inland waterway** Distributary or arm, a subsidiary branch of a river...

NOP 4 0x00000000 This stands for andeq r0, r0, r0 which has no effect at all. The assembly instruction nop will most likely expand to mov r0, r0 witch is encoded 0x01A00000.
MIPS
MIPS architecture
MIPS is a reduced instruction set computer instruction set architecture developed by MIPS Technologies . The early MIPS architectures were 32-bit, and later versions were 64-bit...

NOP 4 0x00000000
MMIX
MMIX
MMIX is a 64-bit RISC instruction set architecture designed by Donald Knuth, with significant contributions by John L. Hennessy and Richard L. Sites...

SWYM 4 0xfd****** SWYM stands for “Sympathize with your machinery.” The * digits can be chosen arbitrarily.
Motorola 68000 family NOP 2 0x4e71
MOS Technology 65xx
MOS Technology 65xx
MOS Technology 65xx is a family of 8-bit microprocessors from MOS Technology, based on the Motorola 6800 . The 65xx family most notably included the 6502, used in several home computers such as the Commodore PET and VIC-20, the Apple II, and the Atari 800.One popular 6502 based computer, the...

NOP 1 0xea NOP consumes two clock cycles.  Undefined opcodes
Illegal opcode
An Illegal Opcode, also called an Undocumented Instruction, is an instruction to a CPU that is not mentioned in any official documentation released by the CPU's designer or manufacturer, which nevertheless has an effect. Illegal opcodes were common on older CPUs designed during the 1970s, such as...

 in the NMOS versions of the 65xx family were converted to be NOPs of varying instruction lengths and cycle times in the 65C02.
PowerPC
PowerPC
PowerPC is a RISC architecture created by the 1991 Apple–IBM–Motorola alliance, known as AIM...

NOP 4 0x60000000 (extended opcode for ori r0,r0,0)
PIC microcontroller
PIC microcontroller
PIC is a family of Harvard architecture microcontrollers made by Microchip Technology, derived from the PIC1650 originally developed by General Instrument's Microelectronics Division...

NOP 12 bits 0b000000000000
SPARC NOP 4 0x01000000
Z80 NOP 1 0x00


From a hardware design point of view, unmapped areas of a bus are often designed to return zeroes; since the NOP slide
NOP slide
In computer CPUs, a NOP slide, NOP sled or NOP ramp is a sequence of NOP instructions meant to "slide" the CPU's instruction execution flow to its final, desired, destination...

 behavior is often desirable, it gives a bias to coding it with the all-zeroes opcode.

NOP 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
Redundant code
Redundant code is a computer programming term for code, which may be source code or compiled code in a computer program, that has any form of redundancy, such as recomputing a value that has previously been calculated and is still available, code that is never executed , or code which is executed...

). A common compiler optimization
Compiler optimization
Compiler optimization is the process of tuning the output of a compiler to minimize or maximize some attributes of an executable computer program. The most common requirement is to minimize the time taken to execute a program; a less common one is to minimize the amount of memory occupied...

 is the detection and removal of this kind of code.

The following is an example of a single C statement that behaves like a NOP (the issue is whether the statement affects program output, not whether or not a compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

 generates any code for this statement):
i+1;

(This statement performs an addition and discards the result.)

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.)
;
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 (ReadChar != '\n')
;

The above code continues calling the function ReadChar until it returns a \n (newline) character.

The Python 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
Off-side rule
A computer programming language is said to adhere to the off-side rule if the scope of declarations in that language is expressed by their indentation. The term and the idea are attributed to Peter J. Landin, and the term can be seen as a pun on the offside law of football .- Definition :Peter J...

; for example the syntax for definition of a class requires an indented block with the class logic, which has to be expressed as pass when it should be empty.

NOP protocol commands

Many computer protocols, such as telnet
TELNET
Telnet is a network protocol used on the Internet or local area networks to provide a bidirectional interactive text-oriented communications facility using a virtual terminal connection...

, 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
Keepalive
A keepalive is a message sent by one device to another to check that the link between the two is operating, or to prevent this link from being broken.-Description:...

 or that the server is responsive. A NOOP command is part of the following protocols (this is a partial list):
  • telnet
    TELNET
    Telnet is a network protocol used on the Internet or local area networks to provide a bidirectional interactive text-oriented communications facility using a virtual terminal connection...

  • FTP
    File Transfer Protocol
    File Transfer Protocol is a standard network protocol used to transfer files from one host to another host over a TCP-based network, such as the Internet. FTP is built on a client-server architecture and utilizes separate control and data connections between the client and server...

  • SMTP
    Simple Mail Transfer Protocol
    Simple Mail Transfer Protocol is an Internet standard for electronic mail transmission across Internet Protocol networks. SMTP was first defined by RFC 821 , and last updated by RFC 5321 which includes the extended SMTP additions, and is the protocol in widespread use today...

  • X11
    X Window core protocol
    The X Window System core protocol is the base protocol of the X Window System, which is a networked windowing system for bitmap displays used to build graphical user interfaces on Unix, Unix-like, and other operating systems...

  • POP3
    Post Office Protocol
    In computing, the Post Office Protocol is an application-layer Internet standard protocol used by local e-mail clients to retrieve e-mail from a remote server over a TCP/IP connection. POP and IMAP are the two most prevalent Internet standard protocols for e-mail retrieval. Virtually all modern...

  • NNTP
    Network News Transfer Protocol
    The Network News Transfer Protocol is an Internet application protocol used for transporting Usenet news articles between news servers and for reading and posting articles by end user client applications...

  • finger
    Finger protocol
    In computer networking, the Name/Finger protocol and the Finger user information protocol are simple network protocols for the exchange of human-oriented status and user information.-Name/Finger protocol:...

  • IMAP4
    Internet Message Access Protocol
    Internet message access protocol is one of the two most prevalent Internet standard protocols for e-mail retrieval, the other being the Post Office Protocol...

  • BitTorrent
  • Character encoding
    Character encoding
    A character encoding system consists of a code that pairs each character from a given repertoire with something else, such as a sequence of natural numbers, octets or electrical pulses, in order to facilitate the transmission of data through telecommunication networks or storage of text in...

    : the null control character
    Control character
    In computing and telecommunication, a control character or non-printing character is a code point in a character set, that does not in itself represent a written symbol.It is in-band signaling in the context of character encoding....


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
Telnet is a network protocol used on the Internet or local area networks to provide a bidirectional interactive text-oriented communications facility using a virtual terminal connection...

 or FTP 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
Minix
MINIX is a Unix-like computer operating system based on a microkernel architecture created by Andrew S. Tanenbaum for educational purposes; MINIX also inspired the creation of the Linux kernel....

 responds to NOOP with the message:
200 NOOP to you too!

Cracking

NOPs are often involved when cracking
Software cracking
Software cracking is the modification of software to remove or disable features which are considered undesirable by the person cracking the software, usually related to protection methods: copy protection, trial/demo version, serial number, hardware key, date checks, CD check or software annoyances...

 software that checks for serial numbers, specific hardware or software requirements, presence or absence of hardware dongle
Dongle
A software protection dongle is a small piece of hardware that plugs into an electrical connector on a computer and serves as an electronic "key" for a piece of software; the program will only run when the dongle is plugged in...

s, etc. This is accomplished by altering functions and subroutines
Subroutine
In computer science, a subroutine is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code....

 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.

Security exploits

The NOP opcode can be used to form a NOP slide
NOP slide
In computer CPUs, a NOP slide, NOP sled or NOP ramp is a sequence of NOP instructions meant to "slide" the CPU's instruction execution flow to its final, desired, destination...

, 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
    Computer architecture
    In computer science and engineering, computer architecture is the practical art of selecting and interconnecting hardware components to create computers that meet functional, performance and cost goals and the formal modelling of those systems....

  • HLT
    HLT
    In the x86 computer architecture, HLT is an assembly language instruction which halts the CPU until the next external interrupt is fired. Such interrupts are used by devices in order to signal to the CPU that an event occurred which the CPU shall react on...

  • Instruction set
    Instruction set
    An instruction set, or instruction set architecture , is the part of the computer architecture related to programming, including the native data types, instructions, registers, addressing modes, memory architecture, interrupt and exception handling, and external I/O...

  • x86
    X86 architecture
    The term x86 refers to a family of instruction set architectures based on the Intel 8086 CPU. The 8086 was launched in 1978 as a fully 16-bit extension of Intel's 8-bit based 8080 microprocessor and also introduced segmentation to overcome the 16-bit addressing barrier of such designs...

  • Identity function
    Identity function
    In mathematics, an identity function, also called identity map or identity transformation, is a function that always returns the same value that was used as its argument...

    , the functional programming
    Functional programming
    In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...

     equivalent to NOOP
  • xyzzy
    Xyzzy
    Xyzzy is a magic word from the Colossal Cave Adventure computer game.In computing, the word is sometimes used as a metasyntactic variable or as a video game cheat code, the canonical "magic word"...

    , a command sometimes used instead of NOOP
  • IEFBR14
    IEFBR14
    IEFBR14 is an IBM mainframe utility program. It runs in all IBM mainframe environments derived from OS/360, including z/OS. It is a placeholder whose purpose is to do nothing...

  • Filler text
    Filler text
    Filler 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-mail spam filter...

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK