2025-04-18 00:22:02 +03:00
|
|
|
namespace X86Disassembler.X86.Handlers.FloatingPoint.Arithmetic;
|
|
|
|
|
|
|
|
using X86Disassembler.X86.Operands;
|
|
|
|
|
|
|
|
/// <summary>
|
2025-04-18 02:37:19 +03:00
|
|
|
/// Handler for FSUBR ST, ST(i) instruction (D8 E8-EF)
|
2025-04-18 00:22:02 +03:00
|
|
|
/// </summary>
|
2025-04-18 02:37:19 +03:00
|
|
|
public class FsubrStStiHandler : InstructionHandler
|
2025-04-18 00:22:02 +03:00
|
|
|
{
|
|
|
|
/// <summary>
|
2025-04-18 02:37:19 +03:00
|
|
|
/// Initializes a new instance of the FsubrStStHandler class
|
2025-04-18 00:22:02 +03:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
2025-04-18 02:37:19 +03:00
|
|
|
public FsubrStStiHandler(InstructionDecoder decoder)
|
2025-04-18 00:22:02 +03:00
|
|
|
: 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 02:37:19 +03:00
|
|
|
// FSUBR ST, ST(i) is D8 E8-EF
|
|
|
|
if (opcode != 0xD8) return false;
|
2025-04-18 00:22:02 +03:00
|
|
|
|
|
|
|
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 E8-EF
|
|
|
|
return secondOpcode is >= 0xE8 and <= 0xEF;
|
2025-04-18 00:22:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2025-04-18 02:37:19 +03:00
|
|
|
/// Decodes a FSUBR ST, ST(i) instruction
|
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 02:31:06 +03:00
|
|
|
// Read the ModR/M byte and calculate ST(i) index
|
|
|
|
var stIndex = (FpuRegisterIndex)(Decoder.ReadByte() - 0xE8);
|
2025-04-18 00:22:02 +03:00
|
|
|
|
|
|
|
// Set the instruction type
|
|
|
|
instruction.Type = InstructionType.Fsubr;
|
|
|
|
|
|
|
|
// Create the FPU register operands
|
|
|
|
var st0Operand = OperandFactory.CreateFPURegisterOperand(FpuRegisterIndex.ST0);
|
2025-04-18 02:37:19 +03:00
|
|
|
var stiOperand = OperandFactory.CreateFPURegisterOperand(stIndex);
|
2025-04-18 00:22:02 +03:00
|
|
|
|
|
|
|
// Set the structured operands
|
|
|
|
instruction.StructuredOperands =
|
|
|
|
[
|
2025-04-18 02:37:19 +03:00
|
|
|
st0Operand,
|
|
|
|
stiOperand
|
2025-04-18 00:22:02 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|