Design of the LLVM disassembler
blog.llvm.org
blog.llvm.org
The most obvious way to write a disassembler (to my mind) specifically for such an idiosyncratic architecture as x86 is a 256-way lookup table mapping the first byte to hand-crafted instruction decoder functions, carefully placed to take advantage of commonalities among certain classes of opcodes. Add some flags into the table and you can extract more commonality. Addressing modes from Mod R/M and SIB can be factored out into separate routines. It adds up to a bunch of grunt work, but ought to be very fast.