0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-06-20 08:18:36 +03:00

Simplified CmpImmWithRm32Handler and added AndImmWithRm32Handler

This commit is contained in:
bird_egop
2025-04-13 23:39:57 +03:00
parent 8d1522b6cb
commit ec70b31058
3 changed files with 111 additions and 15 deletions

View File

@ -48,28 +48,36 @@ public class CmpImmWithRm32Handler : InstructionHandler
// Set the mnemonic
instruction.Mnemonic = "cmp";
// Read the ModR/M byte
var (mod, reg, rm, memOperand) = ModRMDecoder.ReadModRM();
// Get the position after decoding the ModR/M byte
int position = Decoder.GetPosition();
if (position >= Length)
{
return false;
}
// Read the ModR/M byte
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
// Read the immediate value
// Check if we have enough bytes for the immediate value
if (position + 3 >= Length)
{
return false;
return false; // Not enough bytes for the immediate value
}
// Read the immediate value in little-endian format
var imm = Decoder.ReadUInt32();
// Read the immediate value
uint imm32 = Decoder.ReadUInt32();
// Format the immediate value as expected by the tests (0x12345678)
// Note: The bytes are reversed to match the expected format in the tests
string immStr = $"0x{imm:X8}";
// Format the destination operand based on addressing mode
string destOperand;
if (mod == 3) // Register addressing mode
{
// Get 32-bit register name
destOperand = ModRMDecoder.GetRegisterName(rm, 32);
}
else // Memory addressing mode
{
// Memory operand already includes dword ptr prefix
destOperand = memOperand;
}
// Format the immediate value
string immStr = $"0x{imm32:X8}";
// Set the operands
instruction.Operands = $"{destOperand}, {immStr}";