Why is the x86 undefined instruction called ud2? Why 2?

255 points · 59 comments on HN · read original →

Points and comments are a snapshot, not live.

The x86 ud2 instruction's name comes from two earlier undocumented invalid opcodes.

Raymond Chen reconstructs the history of the x86 ud2 instruction. Originally, programmers used the byte sequences 0F FF and 0F B9 to trigger invalid opcode exceptions. Intel later changed these sequences, breaking software that depended on them. To provide a guaranteed invalid opcode, Intel retroactively named 0F FF as ud0, 0F B9 as ud1, and introduced the recommended two-byte ud2. Unlike ud0 and ud1, ud2 has no decoded parameters, avoiding potential page-crossing access violations on older processors.

What commenters are saying

Commenters offer corrections and additional context. One notes that Intel and AMD have since defined UD0, UD1, and UD2 in their manuals, and that x86-64 added a one-byte UDB (D6). Another points out that the original 0F FF sequence (modrm bytes FF FF) is now a documented instruction (UDW), not truly undefined. A question about software interrupts versus UD2 draws multiple replies: while INT instructions can invoke the invalid opcode handler, they require setting up the correct stack frame, making UD2 simpler and more reliable for triggering a guaranteed crash in unreachable code.