namespace X86Disassembler.X86.Handlers.FloatingPoint;
///
/// Handler for FNSTSW AX instruction (0xDF 0xE0)
///
public class FnstswHandler : InstructionHandler
{
///
/// Initializes a new instance of the FnstswHandler class
///
/// The buffer containing the code to decode
/// The instruction decoder that owns this handler
/// The length of the buffer
public FnstswHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
: base(codeBuffer, decoder, length)
{
}
///
/// Checks if this handler can decode the given opcode
///
/// The opcode to check
/// True if this handler can decode the opcode
public override bool CanHandle(byte opcode)
{
// FNSTSW is a two-byte opcode (0xDF 0xE0)
if (opcode == 0xDF)
{
if (!Decoder.CanReadByte())
{
return false;
}
if (CodeBuffer[Decoder.GetPosition()] == 0xE0)
{
return true;
}
}
return false;
}
///
/// Decodes an FNSTSW instruction
///
/// The opcode of the instruction
/// The instruction object to populate
/// True if the instruction was successfully decoded
public override bool Decode(byte opcode, Instruction instruction)
{
// Check if we can read the second byte of the opcode
if (!Decoder.CanReadByte())
{
return false;
}
// Verify the second byte is 0xE0
byte secondByte = CodeBuffer[Decoder.GetPosition()];
if (secondByte != 0xE0)
{
return false;
}
// Skip the second byte of the opcode
Decoder.ReadByte(); // Consume the 0xE0 byte
// Set the mnemonic and operands
instruction.Mnemonic = "fnstsw";
instruction.Operands = "ax";
return true;
}
}