Intel x86 has been the world’s most popular CISC instruction set for generations. The instruction set is huge! What might take several instructions in the MIPS or PowerPC instruction sets can be done in a single instruction with x86. There’s almost as many unique x86 instructions as there are apps for your iPad. Okay, that may be exaggerating a bit, but you get the point.
Questions is, what’s the longest possible instruction in the x86 instruction set? Answer: you can form a valid x86 instruction with an infinite number of bytes! That’s right, you could fill up an entire 64K ROM image with a single valid instruction. To be more specific, there is no limit to the length of x86 instructions. Cool! Unfortunately, modern day i386 variants throw a general protection fault when attempting to decode instructions longer than 15 bytes.
So what does an infinitely-long-but-valid x86 instruction look like? Kinda boring, actually. You could only form an infinitely long instruction by using redundant prefixes in front on the opcodes. Instruction prefixes are bytes pre-pended to the beginning of an instruction that can modify the default address size, data size, or segment registers used by an instruction.
For example, you can take the innocuous looking instruction:
89 E5 mov %sp,%bp
And turn it into a really long instruction:
66 66 66 66 … 66 66 89 E5 mov %sp,%bp
Now that’s just evil.
So what is the longest valid 8086 instruction that isn’t boring and evil? One such example that’s 15 bytes long is below.
lock add DWORD PTR ds:[esi+ecx*4+0x12345678],
If you want to see it in ODA, try these bytes:
67 66 f0 3e 81 84 8e 78 56 34 12 89 ab cd ef
In ODA, you’ll have to manually set the machine mode to i8086. You can do this by clicking the Options button next to the Platform dropdown. Try it out now!
Just remember, next time you’re manually assembling an x86 instruction, don’t go hog wild with those instruction prefixes. ”Everything in moderation, including moderation.” -Oscar Wilde