0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-06-20 08:18:36 +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

@ -47,17 +47,18 @@ public class StringInstructionHandler : InstructionHandler
}
// Check if the opcode is a REP/REPNE prefix followed by a string instruction
if (opcode == REP_PREFIX || opcode == REPNE_PREFIX)
if (opcode != REP_PREFIX && opcode != REPNE_PREFIX)
{
int position = Decoder.GetPosition();
if (position < Length)
{
byte nextByte = CodeBuffer[position];
return StringInstructions.ContainsKey(nextByte);
}
return false;
}
return false;
if (!Decoder.CanReadByte())
{
return false;
}
byte nextByte = CodeBuffer[Decoder.GetPosition()];
return StringInstructions.ContainsKey(nextByte);
}
/// <summary>
@ -79,34 +80,34 @@ public class StringInstructionHandler : InstructionHandler
{
// Set the prefix string based on the prefix opcode
prefixString = opcode == REP_PREFIX ? "rep " : "repne ";
// Read the next byte (the actual string instruction opcode)
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}
stringOpcode = Decoder.ReadByte();
if (!StringInstructions.ContainsKey(stringOpcode))
{
return false;
}
}
// Get the mnemonic and operands for the string instruction
if (StringInstructions.TryGetValue(stringOpcode, out var instructionInfo))
{
// Set the mnemonic with the prefix if present
instruction.Mnemonic = prefixString + instructionInfo.Mnemonic;
// Set the operands
instruction.Operands = instructionInfo.Operands;
return true;
}
// This shouldn't happen if CanHandle is called first
return false;
}
}
}