Jesus Ramos
Jesus Ramos

Reputation: 23266

How to read the direction bit and source or destination of an assembly instruction

So I'm working on some code (for x86) where I need to get the source or destination point of an instruction. For this I need the direction bit which says whether ModRM or REG is the destination or source. Also I need to be able to handle immediate values. So far I can process the instruction and it's primary opcode (along with prefixes). I'm wondering what the easiest way to go about this is or if anyone can point me to some good code examples where the destination/source is determined (such as a register, memory address, or immediate operand). I've seen a lot of decoders but most of them are built specifically for one thing and the ones that do include a lot of functionality are very complex.

Upvotes: 2

Views: 392

Answers (1)

Necrolis
Necrolis

Reputation: 26171

Why not just use a disassembler engine? You can either see how they decode bytes(the specification is in the intel developers manual vol. 1) or get them to do all the heavy lifting for you, so you can instead process their output(which would probably be plain text and a few flags). The two open source engines to look at would be BeaEngine (includes every instruction under the sun, simple to use interface) and ollydbg's disasm engine (simple and compact, only goes up to SSE1 instructions).

Upvotes: 1

Related Questions