namespace X86Disassembler.X86.Handlers.Push; using Operands; /// /// Handler for PUSH imm16 instruction with operand size prefix (0x66 0x68) /// public class PushImm16Handler : InstructionHandler { /// /// Initializes a new instance of the PushImm16Handler class /// /// The instruction decoder that owns this handler public PushImm16Handler(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) { // Check for operand size prefix (66h) followed by PUSH imm (68h) if (opcode != 0x68) { return false; } // Check if we have an operand size prefix return Decoder.HasOperandSizePrefix(); } /// /// Decodes a PUSH 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.Push; // Check if we have enough bytes for the 16-bit immediate if(!Decoder.CanReadUShort()) { return false; } // Read the 16-bit immediate value ushort imm16 = Decoder.ReadUInt16(); // Create an immediate operand with 16-bit size var immOperand = new ImmediateOperand(imm16, 16); // Set the structured operands instruction.StructuredOperands = [ immOperand ]; return true; } }