I want to cause an ARM Cortex-M3 Undefined Instruction exception for the test of my test fixture. The IAR compiler supports this with inline assembly like this:
asm(
There are different official undefined instructions in [1] (look for UDF; . below can be replaced with any hex digit):
0xe7f...f. - ARM or A1 encoding (ARMv4T, ARMv5T, ARMv6, ARMv7, ARMv8)0xde.. - Thumb or T1 encoding (ARMv4T, ARMv5T, ARMv6, ARMv7, ARMv8)0xf7f.a... - Thumb2 or T2 encoding (ARMv6T2, ARMv7, ARMv8)0x0000.... - ARMv8-A permanently undefinedThere are others, but these are probably as future-proof as it gets.
As for generating the code that triggers it, you can just use .short or .word, like this:
asm volatile (".short 0xde00\n"); /* thumb illegal instruction */asm volatile (".word 0xe7f000f0\n"); /* arm illegal instruction */asm volatile (".word 0xe7f0def0\n"); /* arm+thumb illegal instruction */Note that the last one will decode to 0xdef0, 0xe7f0 in thumb context, and therefore also cause an undefined instruction exception.
[1] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.subset.architecture.reference/index.html
[2] DDI0487D_b_armv8_arm.pdf