2025-04-18 00:22:02 +03:00
|
|
|
namespace X86Disassembler.X86.Handlers.FloatingPoint.Comparison;
|
|
|
|
|
|
|
|
using X86Disassembler.X86.Operands;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Handler for FUCOMI instruction (DB E8-EF)
|
|
|
|
/// </summary>
|
|
|
|
public class FucomiHandler : InstructionHandler
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the FucomiHandler class
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
|
|
|
public FucomiHandler(InstructionDecoder decoder)
|
|
|
|
: base(decoder)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks if this handler can decode the given opcode
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="opcode">The opcode to check</param>
|
|
|
|
/// <returns>True if this handler can decode the opcode</returns>
|
|
|
|
public override bool CanHandle(byte opcode)
|
|
|
|
{
|
|
|
|
// FUCOMI is DB E8-EF
|
|
|
|
if (opcode != 0xDB) return false;
|
|
|
|
|
|
|
|
if (!Decoder.CanReadByte())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2025-04-18 02:31:06 +03:00
|
|
|
// Check second opcode byte
|
|
|
|
byte secondOpcode = Decoder.PeakByte();
|
2025-04-18 00:22:02 +03:00
|
|
|
|
2025-04-18 02:31:06 +03:00
|
|
|
// Only handle F0-F7
|
|
|
|
return secondOpcode is >= 0xE8 and <= 0xEF;
|
2025-04-18 00:22:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Decodes a FUCOMI instruction
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="opcode">The opcode of the instruction</param>
|
|
|
|
/// <param name="instruction">The instruction object to populate</param>
|
|
|
|
/// <returns>True if the instruction was successfully decoded</returns>
|
|
|
|
public override bool Decode(byte opcode, Instruction instruction)
|
|
|
|
{
|
|
|
|
if (!Decoder.CanReadByte())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the ModR/M byte
|
2025-04-18 02:31:06 +03:00
|
|
|
var (mod, reg, rm, _) = ModRMDecoder.ReadModRMFpu();
|
2025-04-18 00:22:02 +03:00
|
|
|
|
|
|
|
// Set the instruction type
|
|
|
|
instruction.Type = InstructionType.Fucomi;
|
|
|
|
|
|
|
|
// Create the FPU register operands
|
|
|
|
var destOperand = OperandFactory.CreateFPURegisterOperand(FpuRegisterIndex.ST0);
|
2025-04-18 02:31:06 +03:00
|
|
|
var srcOperand = OperandFactory.CreateFPURegisterOperand(rm);
|
2025-04-18 00:22:02 +03:00
|
|
|
|
|
|
|
// Set the structured operands
|
|
|
|
instruction.StructuredOperands =
|
|
|
|
[
|
|
|
|
destOperand,
|
|
|
|
srcOperand
|
|
|
|
];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|