If I want to write a disassembler program, how can I determine the boundaries of instructions? By "boundaries," I mean the rule of separating a sequence of bytes into individual instructions.
For example, given the codes FF 25 10 00 FF FF 38 11 FF 0A (I made this up), how can we know whether it consists of two instructions FF 25 10 00 FF and FF 38 11 FF 0A, or only one FF 25 10 00 FF FF?
The most direct implementation method that comes to my mind is building an opcode table. When encountering a byte of data, we look it up in the opcode table to find all possible matching instructions (e.g., using a switch case statement). For example, FF can match CALL or JMP instructions. Then we further determine based on the next byte, just like the procedure I take when decoding machine codes myself.
Are there any other smarter ways to achieve this? If so, please let me know.