Raymond Chen, longtime Microsoft blogger, traces the origin of the x86 ud2 instruction on The Old New Thing. Ud2 is an architecturally undefined opcode guaranteed to trigger an invalid-opcode exception, and compilers insert it after code marked unreachable, for instance following a call to a function tagged [[noreturn]] that unexpectedly returns.

Before ud2 existed, developers needed a reliable way to force that exception. One group used the byte sequence 0F FF, another used 0F B9. Both decoded internally as if they took a destination register and a register-or-memory source, values that were never actually read because the exception fired first. When Intel changed later processors and those two sequences stopped reliably raising the exception, existing software broke, an example of Hyrum's Law: with enough users, every observable behavior becomes a dependency for someone.

Intel's fix was to standardize a real, permanently invalid instruction, ud2, a two-byte opcode with no operands. In hindsight 0F FF was renamed ud0 and 0F B9 became ud1, leaving ud2 as the official, recommended choice.

Chen notes a technical downside of ud0 and ud1: because their unused operand bytes still get decoded, hitting one at the end of a memory page can trigger an access violation instead of an invalid-opcode exception if the next page is not present. Some older CPUs raised the invalid-opcode exception as soon as they saw 0F FF, without finishing the decode, producing inconsistent behavior depending on page boundaries. Ud2 avoids this because it is fully self-contained and its behavior is architecturally guaranteed.