2025-04-18 00:22:02 +03:00
|
|
|
namespace X86Disassembler.X86.Handlers.FloatingPoint.Arithmetic;
|
|
|
|
|
|
|
|
using X86Disassembler.X86.Operands;
|
|
|
|
|
|
|
|
/// <summary>
|
2025-04-18 02:31:06 +03:00
|
|
|
/// Handler for FADDP ST(i), ST instruction (DE C0-C7)
|
2025-04-18 00:22:02 +03:00
|
|
|
/// </summary>
|
2025-04-18 02:31:06 +03:00
|
|
|
public class FaddpStiStHandler : InstructionHandler
|
2025-04-18 00:22:02 +03:00
|
|
|
{
|
|
|
|
/// <summary>
|
2025-04-18 02:31:06 +03:00
|
|
|
/// Initializes a new instance of the FaddpStiStHandler 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:31:06 +03:00
|
|
|
public FaddpStiStHandler(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:31:06 +03:00
|
|
|
// FADDP ST(i), ST is DE C0-C7
|
|
|
|
if (opcode != 0xDE) 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 C0-C7
|
|
|
|
return secondOpcode is >= 0xC0 and <= 0xC7;
|
2025-04-18 00:22:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2025-04-18 02:31:06 +03:00
|
|
|
/// Decodes a FADDP ST(i), ST 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() - 0xC0);
|
2025-04-18 00:22:02 +03:00
|
|
|
|
|
|
|
// Set the instruction type
|
2025-04-18 02:31:06 +03:00
|
|
|
instruction.Type = InstructionType.Faddp;
|
2025-04-18 00:22:02 +03:00
|
|
|
|
|
|
|
// Create the FPU register operands
|
|
|
|
var stiOperand = OperandFactory.CreateFPURegisterOperand(stIndex);
|
|
|
|
var st0Operand = OperandFactory.CreateFPURegisterOperand(FpuRegisterIndex.ST0);
|
|
|
|
|
|
|
|
// Set the structured operands
|
|
|
|
instruction.StructuredOperands =
|
|
|
|
[
|
|
|
|
stiOperand,
|
|
|
|
st0Operand
|
|
|
|
];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|