mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-05-21 21:01:17 +03:00
Simplified FnstswHandler by using CanReadByte for boundary checking and improving code readability
This commit is contained in:
parent
ec1aa4a124
commit
7ab388f26d
@ -1,7 +1,7 @@
|
|||||||
namespace X86Disassembler.X86.Handlers.FloatingPoint;
|
namespace X86Disassembler.X86.Handlers.FloatingPoint;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handler for FNSTSW instruction (0xDFE0)
|
/// Handler for FNSTSW AX instruction (0xDF 0xE0)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class FnstswHandler : InstructionHandler
|
public class FnstswHandler : InstructionHandler
|
||||||
{
|
{
|
||||||
@ -26,8 +26,12 @@ public class FnstswHandler : InstructionHandler
|
|||||||
// FNSTSW is a two-byte opcode (0xDF 0xE0)
|
// FNSTSW is a two-byte opcode (0xDF 0xE0)
|
||||||
if (opcode == 0xDF)
|
if (opcode == 0xDF)
|
||||||
{
|
{
|
||||||
int position = Decoder.GetPosition();
|
if (!Decoder.CanReadByte())
|
||||||
if (position < Length && CodeBuffer[position] == 0xE0)
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CodeBuffer[Decoder.GetPosition()] == 0xE0)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -44,15 +48,21 @@ public class FnstswHandler : InstructionHandler
|
|||||||
/// <returns>True if the instruction was successfully decoded</returns>
|
/// <returns>True if the instruction was successfully decoded</returns>
|
||||||
public override bool Decode(byte opcode, Instruction instruction)
|
public override bool Decode(byte opcode, Instruction instruction)
|
||||||
{
|
{
|
||||||
int position = Decoder.GetPosition();
|
// Check if we can read the second byte of the opcode
|
||||||
|
if (!Decoder.CanReadByte())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (position >= Length || CodeBuffer[position] != 0xE0)
|
// Verify the second byte is 0xE0
|
||||||
|
byte secondByte = CodeBuffer[Decoder.GetPosition()];
|
||||||
|
if (secondByte != 0xE0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip the second byte of the opcode
|
// Skip the second byte of the opcode
|
||||||
Decoder.SetPosition(position + 1);
|
Decoder.ReadByte(); // Consume the 0xE0 byte
|
||||||
|
|
||||||
// Set the mnemonic and operands
|
// Set the mnemonic and operands
|
||||||
instruction.Mnemonic = "fnstsw";
|
instruction.Mnemonic = "fnstsw";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user