0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-08-05 02:26:33 +03:00

more refactoring

This commit is contained in:
bird_egop
2025-04-14 01:08:14 +03:00
parent f54dc10596
commit 99b93523a4
78 changed files with 379 additions and 594 deletions

View File

@@ -37,16 +37,13 @@ public class CmpAlImmHandler : InstructionHandler
// Set the mnemonic
instruction.Mnemonic = "cmp";
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}
// Read the immediate value
byte imm8 = Decoder.ReadByte();
Decoder.SetPosition(position);
// Set the operands
instruction.Operands = $"al, 0x{imm8:X2}";

View File

@@ -27,11 +27,10 @@ public class CmpImmWithRm32Handler : InstructionHandler
return false;
// Check if the reg field of the ModR/M byte is 7 (CMP)
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
return false;
byte modRM = CodeBuffer[position];
byte modRM = CodeBuffer[Decoder.GetPosition()];
byte reg = (byte) ((modRM & 0x38) >> 3);
return reg == 7; // 7 = CMP
@@ -55,7 +54,7 @@ public class CmpImmWithRm32Handler : InstructionHandler
int position = Decoder.GetPosition();
// Check if we have enough bytes for the immediate value
if (position + 3 >= Length)
if (!Decoder.CanReadUInt())
{
return false; // Not enough bytes for the immediate value
}

View File

@@ -28,7 +28,7 @@ public class CmpImmWithRm32SignExtendedHandler : InstructionHandler
// Check if the reg field of the ModR/M byte is 7 (CMP)
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
return false;
byte modRM = CodeBuffer[position];
@@ -50,7 +50,7 @@ public class CmpImmWithRm32SignExtendedHandler : InstructionHandler
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}
@@ -59,14 +59,13 @@ public class CmpImmWithRm32SignExtendedHandler : InstructionHandler
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
// Read the immediate value
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}
// Read the immediate value as a signed byte and sign-extend it
sbyte imm8 = (sbyte) Decoder.ReadByte();
Decoder.SetPosition(position);
// Set the operands
instruction.Operands = $"{destOperand}, 0x{(uint) imm8:X2}";

View File

@@ -55,7 +55,7 @@ public class CmpImmWithRm8Handler : InstructionHandler
int position = Decoder.GetPosition();
// Check if we have enough bytes for the immediate value
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false; // Not enough bytes for the immediate value
}

View File

@@ -34,9 +34,7 @@ public class CmpR32Rm32Handler : InstructionHandler
/// <returns>True if the instruction was successfully decoded</returns>
public override bool Decode(byte opcode, Instruction instruction)
{
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}

View File

@@ -36,11 +36,8 @@ public class CmpRm32R32Handler : InstructionHandler
{
// Set the mnemonic
instruction.Mnemonic = "cmp";
// Save the original position to properly handle the ModR/M byte
int originalPosition = Decoder.GetPosition();
if (originalPosition >= Length)
if (!Decoder.CanReadByte())
{
return false;
}