Raise an Illegal Instruction in RISC-V on Purpose

What is the simplest, most readable and straightforward way to raise an illegal instruction in RISC-V on purpose?

I know that per spec any "full zero" instruction (so 32/16 bits only zeros) is a "Defined Illegal Instruction" (section 12.5, user spec). But I have no idea if there exists an asm shorthand for that (at least I could not find any) that I could then use in inline asm in C code.

There must surely be a portable and reliable way to always cause an illegal instruction exception? I personally find writing to read-only registers or similar hacks quite offputting, as they are not very explicit. But maybe this is just how its done?

Thank you in advance

>Solution :

The mnemonic for it is unimp. It is documented in the RISC-V asm manual, so it should be portable.

Leave a Reply