2025-04-18 00:22:02 +03:00
|
|
|
namespace X86Disassembler.X86.Handlers.FloatingPoint.Comparison;
|
|
|
|
|
|
|
|
using X86Disassembler.X86.Operands;
|
|
|
|
|
|
|
|
/// <summary>
|
2025-04-18 01:25:34 +03:00
|
|
|
/// Handler for FCOMP ST(i) instruction (D8 D8-DF) - compares ST(0) with ST(i) and pops the register stack
|
2025-04-18 00:22:02 +03:00
|
|
|
/// </summary>
|
|
|
|
public class FcompStHandler : InstructionHandler
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the FcompStHandler class
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
|
|
|
public FcompStHandler(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)
|
|
|
|
{
|
2025-04-18 01:25:34 +03:00
|
|
|
// FCOMP ST(i) is D8 D8-DF (compares ST(0) with ST(i) and pops the register stack)
|
|
|
|
if (opcode != 0xD8) return false;
|
2025-04-18 00:22:02 +03:00
|
|
|
|
|
|
|
if (!Decoder.CanReadByte())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2025-04-18 01:25:34 +03:00
|
|
|
var opcodeSecond = Decoder.PeakByte();
|
|
|
|
|
|
|
|
// this is a special case of a handler, only handling FCOMP with ST(i)
|
|
|
|
if (opcodeSecond < 0xD8 || opcodeSecond > 0xDF)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2025-04-18 00:22:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2025-04-18 01:25:34 +03:00
|
|
|
/// Decodes a FCOMP ST(i) instruction - compares ST(0) with ST(i) and pops the register stack
|
2025-04-18 00:22:02 +03:00
|
|
|
/// </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;
|
|
|
|
}
|
|
|
|
|
2025-04-18 01:25:34 +03:00
|
|
|
var stIndex = (FpuRegisterIndex)(Decoder.ReadByte() - 0xD8);
|
|
|
|
|
2025-04-18 00:22:02 +03:00
|
|
|
// Set the instruction type
|
|
|
|
instruction.Type = InstructionType.Fcomp;
|
2025-04-18 01:25:34 +03:00
|
|
|
|
|
|
|
// Create the FPU register operands
|
|
|
|
var stiOperand = OperandFactory.CreateFPURegisterOperand(stIndex);
|
2025-04-18 00:22:02 +03:00
|
|
|
|
|
|
|
// Set the structured operands
|
|
|
|
instruction.StructuredOperands =
|
|
|
|
[
|
2025-04-18 01:25:34 +03:00
|
|
|
stiOperand // The instruction is FCOMP ST(i), which compares ST(0) with ST(i) and pops the register stack
|
2025-04-18 00:22:02 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|