ArticleslgStudy

computer science

Illegal opcode

Illegal opcode is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Illegal opcode rather than just read about it. In short: In computer science, an illegal opcode, also called an unimplemented operation, unintended opcode or 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 the MOS Technology 6502, Intel 8086, and the Zilog Z80.

Illegal opcode — main illustration
Illegal opcode — illustration

Key takeaways

  • Illegal opcode belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Illegal opcode to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Illegal opcode from memory before moving on to harder problems.

Reference excerpt

In computer science, an illegal opcode, also called an unimplemented operation, unintended opcode or 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 the MOS Technology 6502, Intel 8086, and the Zilog Z80. Unlike modern processors, those older processors have a very limited transistor budget, and thus to save space their designers often omitted circuitry to detect invalid opcodes and generate a trap to an error handler. The operation of many of these opcodes happens as a side effect of the wiring of transistors in the CPU, and usually combines functions of the CPU that were not intended to be combined. On old and modern processors, there are also instructions intentionally included in the processor by the manufacturer, but that are not documented in any official specification.

Overview While most accidental illegal instructions have useless or even highly undesirable effects (such as crashing the device), some can have useful functions in certain situations. Such instructions were sometimes exploited in computer games of the 1970s and 1980s to speed up certain time-critical sections. Another common use was in the ongoing battle between copy protection implementations and cracking. Here, they were a form of security through obscurity, and their secrecy usually did not last very long. A danger associated with the use of illegal instructions was that, given the fact that the manufacturer does not 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 did not work correctly on the newer Apple IIc, because the latter used a newer CPU revision – 65C02 – that did away with illegal opcodes. Later CPUs, such as the 80186, 80286, 68000 and its descendants, do not have illegal opcodes that are widely known/used. Ideally, the CPU will behave in a well-defined way when it finds an unknown opcode in the instruction stream, such as triggering a certain exception or fault condition. The operating system's exception or fault handler will then usually terminate the application that caused the fault, unless the program had previously established its own exception/fault handler, in which case that handler would receive control. Another, less common way of handling illegal instructions is by defining them to do nothing except taking up time and space (equivalent to the CPU's official NOP instruction); this method is used by the TMS9900 and 65C02 processors, among others. Alternatively, unknown instructions can be emulated in software (e.g. LOADALL), or even "new" pseudo-instructions can be implemented. Some BIOSes, memory managers, and operating systems take advantage of this, for example, to let V86 tasks communicate with the underlying system, i.e. BOP (from "BIOS Operation") utilized by the Windows NTVDM. In spite of Intel's guarantee against such instructions, research using techniques such as fuzzing uncovered a vast number of undocumented instructions in x86 processors as late as 2018. Some of these instructions are shared across processor manufacturers, indicating that Intel and AMD are both aware of the instruction and its purpose, despite it not appearing in any official specification. Other instructions are specific to manufacturers or specific product lines. The purpose of the majority of x86 undocumented instructions is unknown. Today, the details of these instructions are mainly of interest for exact emulation of older systems.

See also Don't-care term Gadget (machine instruction sequence) Halt and Catch Fire (computing) List of x86 instructions#Undocumented x86 instructions Microcode Pentium F00F bug Synthetic programming Trap (computing) Undocumented feature

References

Further reading Vardy, Adam (1996-09-27) [1995-08-22]. "Extra Instructions Of The 65XX Series CPU". Archived from the original on 2021-08-28. Retrieved 2021-11-18. (NB. Illegal opcodes on the 6502.) Steil, Michael (2008-07-29). "How MOS 6502 Illegal Opcodes really work". pagetable.com - Some Assembly Required. Archived from the original on 2021-11-19. Retrieved 2021-11-18. Young, Sean (2005-09-18) [1997]. "Z80 Documentation: The Undocumented Z80 Documented". 0.91. Archived from the original on 2021-10-09. Retrieved 2021-11-18. (NB. Illegal opcodes on the Z80.) Brown, Ralf D., ed. (2002-12-29) [2000-07-17, 1985]. "The x86 Interrupt List" (61 ed.). Archived from the original on 2017-08-22. Retrieved 2011-10-14. [3][4][5][6][7][8][9] (NB. Ralf Brown's Interrupt List's also contains some information about undocumented processor opcodes and processor bugs: OPCODES.LST by Alex V. Potemkin and 86BUGS.LST by Harald Feldmann.)

External links Christian Ludloff's site sandpile.org also contains info on undocumented opcodes

Illustrations

Illegal opcode: A deliberately triggered illegal instruction signal
A deliberately triggered illegal instruction signal

Worked examples

Example 1 — a first encounter with Illegal opcode

Start with the simplest possible case. Write down what Illegal opcode claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Illegal opcode before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Illegal opcode ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Illegal opcode

In research
Illegal opcode appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Illegal opcode in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Illegal opcode is common in secondary-school and first-year university syllabi. It links to neighbouring topics Machine code, Software anomalies, so understanding it makes those chapters shorter.
In everyday life
Look for Illegal opcode outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Illegal opcode” →

How to study Illegal opcode in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Illegal opcode means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Illegal opcode out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Illegal opcode in simple terms?

In computer science, an illegal opcode, also called an unimplemented operation, unintended opcode or 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 opc…

Why does Illegal opcode matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Illegal opcode?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Illegal opcode.

Tags

  • Machine code
  • Software anomalies

Keep exploring