3 ms·
Because x86 instruction encoding is a mess. Take a look at this[1] flowchart from the amd manual (vol. 3). That doesn't even tell the whole story; there's a t
by moonchild 6y ago
Because x86 instruction encoding is a mess. Take a look at this[1] flowchart from the amd manual (vol. 3).
That doesn't even tell the whole story; there's a ton of path dependence, and the operand format is quite complicated and has tons of special cases.
1. https://0x0.st/-rce.png https://0x0.st/-rce.png
- jart 6y agoI thought x86 was pretty straightforward once I understood the octal encoding. Cosmopolitan provides a 3kb x86 instruction length decoder that supports all past, present, and future ISAs: https://github.com/jart/cosmopolitan/blob/master/third_party/xed/x86ild.greg.c https://github.com/jart/cosmopolitan/blob/master/third_party... The Cosmopolitan codebase also provides a debugger / emulator for i8086 + x86-64 that's similar to GDB TUI and Bochs. See https://justine.lol/blinkenlights/index.html https://justine.lol/blinkenlights/index.html For example, here's the ALU code: https://github.com/jart/cosmopolitan/blob/master/tool/build/lib/alu.c https://github.com/jart/cosmopolitan/blob/master/tool/build/...
- Someone 6y agoI wouldn’t call 3kb “pretty straightforward”, certainly not relative to the competition. The instruction length decoder for quite a few CPUs is return INSTRUCTION_SIZE; I don’t know any other that has more than a few cases for immediate constants and jump addresses.
- dnautics 6y agoxoreaxeaxeax's videos about how to systematically parse the asm space of x86 really hit home to me how bad the encoding is. https://www.youtube.com/watch?v=KrksBdWcZgQ https://www.youtube.com/watch?v=KrksBdWcZgQ