using X86Disassembler.X86.Operands; namespace X86Disassembler.X86.Handlers.And; /// /// Handler for AND AX, imm16 instruction (0x25 with 0x66 prefix) /// public class AndAxImmHandler : InstructionHandler { /// /// Initializes a new instance of the AndAxImmHandler class /// /// The instruction decoder that owns this handler public AndAxImmHandler(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) { // AND AX, imm16 is encoded as 0x25 with 0x66 prefix if (opcode != 0x25) { return false; } // Only handle when the operand size prefix is present return Decoder.HasOperandSizePrefix(); } /// /// Decodes an AND AX, imm16 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.And; // Check if we have enough bytes for the immediate value if (!Decoder.CanReadUShort()) { return false; } // Read the immediate value ushort imm16 = Decoder.ReadUInt16(); // Create the AX register operand var axOperand = OperandFactory.CreateRegisterOperand(RegisterIndex.A, 16); // Create the immediate operand var immOperand = OperandFactory.CreateImmediateOperand(imm16); // Set the structured operands instruction.StructuredOperands = [ axOperand, immOperand ]; return true; } }