namespace X86Disassembler.X86.Handlers.Inc;
using X86Disassembler.X86.Operands;
///
/// Handler for INC r32 instructions (0x40-0x47)
///
public class IncRegHandler : InstructionHandler
{
///
/// Initializes a new instance of the IncRegHandler class
///
/// The instruction decoder that owns this handler
public IncRegHandler(InstructionDecoder decoder)
: base(decoder)
{
}
///
/// Checks if this handler can decode the given opcode
///
/// The opcode to check
/// True if this handler can decode the opcode
public override bool CanHandle(byte opcode)
{
// INC EAX = 0x40, INC ECX = 0x41, ..., INC EDI = 0x47
return opcode >= 0x40 && opcode <= 0x47;
}
///
/// Decodes an INC r32 instruction
///
/// The opcode of the instruction
/// The instruction object to populate
/// True if the instruction was successfully decoded
public override bool Decode(byte opcode, Instruction instruction)
{
// Calculate the register index (0 for EAX, 1 for ECX, etc.)
RegisterIndex reg = (RegisterIndex)(byte)(opcode - 0x40);
// Set the instruction type
instruction.Type = InstructionType.Inc;
// Create the register operand
var regOperand = OperandFactory.CreateRegisterOperand(reg, 32);
// Set the structured operands
instruction.StructuredOperands =
[
regOperand
];
return true;
}
}