mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 08:18:36 +03:00
more refactoring
This commit is contained in:
@ -34,9 +34,7 @@ public class SubAlImm8Handler : 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;
|
||||
}
|
||||
|
@ -38,10 +38,7 @@ public class SubAxImm16Handler : InstructionHandler
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "sub";
|
||||
|
||||
int position = Decoder.GetPosition();
|
||||
|
||||
// Check if we have enough bytes for the immediate value
|
||||
if (position + 1 >= Length)
|
||||
if (!Decoder.CanReadUShort())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -27,11 +27,10 @@ public class SubImmFromRm32Handler : InstructionHandler
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 5 (SUB)
|
||||
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 == 5; // 5 = SUB
|
||||
@ -48,25 +47,16 @@ public class SubImmFromRm32Handler : InstructionHandler
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "sub";
|
||||
|
||||
int position = Decoder.GetPosition();
|
||||
|
||||
if (position >= Length)
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
|
||||
// Extract the fields from the ModR/M byte
|
||||
// Let the ModRMDecoder handle the ModR/M byte and any additional bytes (SIB, displacement)
|
||||
// This will update the decoder position to point after the ModR/M and any additional bytes
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Get the updated position after ModR/M decoding
|
||||
position = Decoder.GetPosition();
|
||||
|
||||
// Read the immediate value
|
||||
if (position + 3 >= Length)
|
||||
if (!Decoder.CanReadUInt())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -27,11 +27,10 @@ public class SubImmFromRm8Handler : InstructionHandler
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 5 (SUB)
|
||||
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 == 5; // 5 = SUB
|
||||
@ -52,8 +51,7 @@ public class SubImmFromRm8Handler : InstructionHandler
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Read the immediate byte
|
||||
var position = Decoder.GetPosition();
|
||||
if (position >= Length)
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -38,9 +38,7 @@ public class SubR16Rm16Handler : InstructionHandler
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "sub";
|
||||
|
||||
int position = Decoder.GetPosition();
|
||||
|
||||
if (position >= Length)
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -34,9 +34,7 @@ public class SubR32Rm32Handler : 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;
|
||||
}
|
||||
|
@ -37,9 +37,7 @@ public class SubR8Rm8Handler : InstructionHandler
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "sub";
|
||||
|
||||
int position = Decoder.GetPosition();
|
||||
|
||||
if (position >= Length)
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -38,9 +38,7 @@ public class SubRm16R16Handler : InstructionHandler
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "sub";
|
||||
|
||||
int position = Decoder.GetPosition();
|
||||
|
||||
if (position >= Length)
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -59,7 +57,6 @@ public class SubRm16R16Handler : InstructionHandler
|
||||
}
|
||||
else // Memory operand
|
||||
{
|
||||
// Replace "dword" with "word" in the memory operand
|
||||
destOperand = destOperand.Replace("dword", "word");
|
||||
|
||||
instruction.Operands = $"{destOperand}, {regName}";
|
||||
|
@ -34,9 +34,7 @@ public class SubRm32R32Handler : 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;
|
||||
}
|
||||
|
@ -37,9 +37,7 @@ public class SubRm8R8Handler : InstructionHandler
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "sub";
|
||||
|
||||
int position = Decoder.GetPosition();
|
||||
|
||||
if (position >= Length)
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user