Simple: ud2
(0F 0B
)
Its entire purpose is to raise an Invalid Opcode Exception.
Question
I am trying to create a program which generates an illegal instruction exception for demonstration purposes.
There seems to be a simple solution to my problem:
cmpxchgl %edx, %ecx
But rather than giving me an exception at runtime, the compiler (FASM) doesn't want to compile the code. It says "Illegal instruction" (and that's probably right, actually nice to warn me before).
Any solution for getting an illegal instruction exception is fine for me, so you could
a) point me to another compiler which simply compiles the code
b) apply a workaround for my command
c) propose a completely different command (should be simple, oneliners preferred)
Solution
Simple: ud2
(0F 0B
)
Its entire purpose is to raise an Invalid Opcode Exception.
OTHER TIPS
You could have looked up the machine code yourself from the instruction set reference.
I have done it for you, cmpxchgl %edx, %ecx
is 0x0F 0xB1 0xCA
. Just stick those into your code as DB
or .byte
or whatever your compiler supports.
By the way, GAS
assembles it without a word.