diff --git a/X86Disassembler/X86/Handlers/FloatingPointHandler.cs b/X86Disassembler/X86/Handlers/FloatingPointHandler.cs index 9902f48..b24f36c 100644 --- a/X86Disassembler/X86/Handlers/FloatingPointHandler.cs +++ b/X86Disassembler/X86/Handlers/FloatingPointHandler.cs @@ -8,12 +8,16 @@ public class FloatingPointHandler : InstructionHandler // Floating-point instruction mnemonics based on opcode and ModR/M reg field private static readonly string[][] FpuMnemonics = new string[8][]; + // Two-byte floating-point instructions + private static readonly Dictionary TwoByteInstructions = new Dictionary(); + /// /// Static constructor to initialize the FPU mnemonic tables /// static FloatingPointHandler() { InitializeFpuMnemonics(); + InitializeTwoByteInstructions(); } /// @@ -105,6 +109,17 @@ public class FloatingPointHandler : InstructionHandler FpuMnemonics[7][7] = "fistp"; } + /// + /// Initializes the two-byte floating-point instructions + /// + private static void InitializeTwoByteInstructions() + { + // DF E0 - FNSTSW AX (Store FPU status word to AX without checking for pending unmasked floating-point exceptions) + TwoByteInstructions.Add(0xDFE0, "fnstsw"); + + // Add other two-byte instructions as needed + } + /// /// Initializes a new instance of the FloatingPointHandler class /// @@ -141,6 +156,27 @@ public class FloatingPointHandler : InstructionHandler return false; } + // Check for two-byte instructions + if (position < Length) + { + // Create a two-byte opcode by combining the primary opcode with the next byte + ushort twoByteOpcode = (ushort)((opcode << 8) | CodeBuffer[position]); + + // Check if this is a known two-byte instruction + if (TwoByteInstructions.TryGetValue(twoByteOpcode, out string? mnemonic) && mnemonic != null) + { + instruction.Mnemonic = mnemonic; + + // Special handling for specific instructions + if (twoByteOpcode == 0xDFE0) // FNSTSW AX + { + instruction.Operands = "ax"; + Decoder.SetPosition(position + 1); // Skip the second byte + return true; + } + } + } + // The opcode index in our tables (0-7 for D8-DF) int opcodeIndex = opcode - 0xD8;