NOP
From Wikipedia, the free encyclopedia
- For other uses, see NOP (disambiguation).
NOP or NOOP (short for No OPeration) is an assembly language instruction, sequence of programming language statements, or computer protocol command that does nothing at all (besides wasting clock cycles).
Contents |
[edit] NOP Machine Instruction
Most computer instruction sets include an instruction that does nothing for a specific number of clock cycles; it makes no changes to memory or program status. NOPs are most commonly used for timing purposes, to force memory alignment, to prevent hazards, to occupy a branch delay slot, or as a "place-holder" to be replaced by active instructions later on in program development. The characteristics of the NOP instruction for the Intel x86 CPU family are:
The Intel 8080 and Zilog Z80 use the opcode 0x00 for NOP. In the MOS Technology 6502 and its descandant processors, NOP has the opcode 0xEA. The Motorola 68000 processor's NOP instruction has the opcode 0x4E71.
[edit] NOOP code
NOOP can also be used as a description for what a function or sequence of programming language statements does. If the function or code has no effect, then it could be called a noop.
An example of a single C statement that would also produce a NOOP:
i+1;
(This statement would perform an addition but discard the result.)
The simplest possible NOOP statement in C is the empty statement
;
The empty statement is useless by itself, but can be useful in the context of a loop, e.g.:
while (ReadChar() != '\n');
The above code continues calling the function ReadChar until it returns a \n (newline) character.
Today, optimizing compilers search for noop statements in code. As the function or piece of code does nothing, the compiler simply removes it. Many optimizing compilers include a directive by which a programmer can explicitly disable this optimization, thereby including code that appears to be a noop to the optimizing compiler. This is useful for cases in which removing the code would cause a bug.
[edit] NOOP 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 NOP command has a specific purpose which is to allow the client to request that the server send unsolicited information reflecting the actions of other clients.
While most telnet servers respond to a NOOP command with "OK" or "+OK", some programmers have added quirky responses to noop. Some examples:
noop : OK, but why? :) noop : Well, noop to you too!
[edit] 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 is accomplished by altering functions and subroutines such that, rather than completing their assigned task(s), they simply return a Boolean value of "true" or "false" (or whichever other parameter was being checked for).
A pseudocode example of such usage is as follows. The original unmodified subroutine:
on checkForSerialNumber(theSerialNumber) set serialNumberValidity to false if theSerialNumber is in {abc123, def456, ghi789} then set serialNumberValidity to true else display dialog {"The serial number was not valid."} alertAuthoritiesToPiracy end if return serialNumberValidity end checkForSerialNumber
The modified subroutine, where statements marked with "#
" have been replaced with NOP instructions:
on checkForSerialNumber(theSerialNumber) #set serialNumberValidity to false #if theSerialNumber is in {abc123, def456, ghi789} then set serialNumberValidity to true #else # display dialog {"The serial number was not valid."} # alertAuthoritiesToPiracy #end if return serialNumberValidity end checkForSerialNumber
The raw, uncompiled source code of commercial applications is not typically made available to the general public. Because of this, reverse engineering with various software tools is typically necessary in order to determine the actual hexadecimal bytes that must be edited in the final, compiled code, so as to insert the appropriate NOP(s) where necessary.