namespace X86Disassembler.X86.Handlers.Adc; using Operands; /// /// Handler for ADC AX/EAX, imm16/32 instruction (opcode 0x15) /// public class AdcAccumulatorImmHandler : InstructionHandler { /// /// Initializes a new instance of the AdcAccumulatorImmHandler class /// /// The instruction decoder that owns this handler public AdcAccumulatorImmHandler(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) { // ADC AX/EAX, imm16/32 is encoded as 0x15 return opcode == 0x15; } /// /// Decodes a ADC AX/EAX, imm16/32 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) { // Set the instruction type instruction.Type = InstructionType.Adc; // Determine operand size based on prefix int operandSize = Decoder.HasOperandSizePrefix() ? 16 : 32; // Check if we have enough bytes for the immediate value if (operandSize == 16 && !Decoder.CanReadUShort()) { return false; } else if (operandSize == 32 && !Decoder.CanReadUInt()) { return false; } // Create the accumulator register operand (AX or EAX) var accumulatorOperand = OperandFactory.CreateRegisterOperand(RegisterIndex.A, operandSize); // Read and create the immediate operand based on operand size var immOperand = operandSize == 16 ? OperandFactory.CreateImmediateOperand(Decoder.ReadUInt16(), operandSize) : OperandFactory.CreateImmediateOperand(Decoder.ReadUInt32(), operandSize); // Set the structured operands instruction.StructuredOperands = [ accumulatorOperand, immOperand ]; return true; } }