- 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 theMOS Technology 6502 ,Intel 8086 and theZilog Z80 . They exist as a side-effect of the wiring of transistors in the CPU, and usually combine functions of the CPU that were not intended to be combined.While most illegal instructions have useless or even highly undesirable effects (such as crashing the computer), a few might by accident do something that can be useful in certain situations. Such instructions were sometimes exploited in
computer game s of the 1970s and 1980s to speed up certain time-critical sections. Another common use of them was in the ongoing battle betweencopy protection implementations and cracking. Here, they were a form ofsecurity through obscurity , and their secrecy usually didn't last very long.A danger associated with the use of illegal instructions was that, given the fact that the manufacturer didn't guarantee their existence and function, they might disappear or behave differently with any change of the CPU internals or any new revision of the CPU, rendering programs that use them incompatible with the newer revisions. For example, a number of older
Apple II games don't work correctly on the newerApple IIc , because the latter uses a newer CPU revision that does away with illegal opcodes.Modern CPUs, such as the
80186 ,80286 and its descendants or thePowerPC processor, usually don't have illegal opcodes. Their manufacturers guarantee that the CPU will behave in a well-defined way when it finds an unknown opcode in the instruction stream: usually, this means triggering a certain exception or fault condition. Theoperating system 's exception or fault handler will then usually terminate the application that caused the fault. Another, less common way of handling illegal instructions is by defining them to do nothing (equivalent to the CPU's officialNOP instruction); this method is used by the65C02 processor, among others.Today, the details of these instructions are mainly of interest for exact
emulation of older systems.Sources
*Illegal opcodes on the 6502: http://www.ffd2.com/fridge/docs/6502-NMOS.extra.opcodes
*Illegal opcodes on the Z80: http://www.myquest.nl/z80undocumented/
Wikimedia Foundation. 2010.