mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-05-19 20:01:17 +03:00
Simplified AndImmToRm8Handler for better maintainability and consistency
This commit is contained in:
parent
cf1e1acf71
commit
f19f2254fe
@ -54,40 +54,40 @@ public class AndImmToRm8Handler : InstructionHandler
|
|||||||
// Set the mnemonic
|
// Set the mnemonic
|
||||||
instruction.Mnemonic = "and";
|
instruction.Mnemonic = "and";
|
||||||
|
|
||||||
int position = Decoder.GetPosition();
|
|
||||||
|
|
||||||
// Read the ModR/M byte
|
// Read the ModR/M byte
|
||||||
var (mod, reg, rm, memOperand) = ModRMDecoder.ReadModRM();
|
var (mod, reg, rm, memOperand) = ModRMDecoder.ReadModRM();
|
||||||
|
|
||||||
// Read immediate value
|
// Get the position after decoding the ModR/M byte
|
||||||
|
int position = Decoder.GetPosition();
|
||||||
|
|
||||||
|
// Check if we have enough bytes for the immediate value
|
||||||
if (position >= Length)
|
if (position >= Length)
|
||||||
{
|
{
|
||||||
// Incomplete instruction
|
return false; // Not enough bytes for the immediate value
|
||||||
if (mod == 3)
|
|
||||||
{
|
|
||||||
string rmRegName = ModRMDecoder.GetRegisterName(rm, 8);
|
|
||||||
instruction.Operands = $"{rmRegName}, ??";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
instruction.Operands = $"byte ptr {memOperand}, ??";
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read the immediate value
|
||||||
byte imm8 = Decoder.ReadByte();
|
byte imm8 = Decoder.ReadByte();
|
||||||
|
|
||||||
// Set operands
|
// Format the destination operand based on addressing mode
|
||||||
if (mod == 3)
|
string destOperand;
|
||||||
|
if (mod == 3) // Register addressing mode
|
||||||
{
|
{
|
||||||
string rmRegName = ModRMDecoder.GetRegisterName(rm, 8);
|
// Get 8-bit register name
|
||||||
instruction.Operands = $"{rmRegName}, 0x{imm8:X2}";
|
destOperand = ModRMDecoder.GetRegisterName(rm, 8);
|
||||||
}
|
}
|
||||||
else
|
else // Memory addressing mode
|
||||||
{
|
{
|
||||||
instruction.Operands = $"byte ptr {memOperand}, 0x{imm8:X2}";
|
// Add byte ptr prefix for memory operands
|
||||||
|
destOperand = $"byte ptr {memOperand}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Format the immediate value
|
||||||
|
string immStr = $"0x{imm8:X2}";
|
||||||
|
|
||||||
|
// Set the operands
|
||||||
|
instruction.Operands = $"{destOperand}, {immStr}";
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user