namespace X86Disassembler.X86.Handlers.Ret;
using Operands;
///
/// Handler for RET instruction with immediate operand (0xC2)
///
public class RetImmHandler : InstructionHandler
{
///
/// Initializes a new instance of the RetImmHandler class
///
/// The instruction decoder that owns this handler
public RetImmHandler(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)
{
// Only handle opcode 0xC2 when the operand size prefix is NOT present
// This ensures 16-bit handlers get priority when the prefix is present
return opcode == 0xC2 && !Decoder.HasOperandSizePrefix();
}
///
/// Decodes a RET instruction with immediate operand
///
/// 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.Ret;
if (!Decoder.CanReadUShort())
{
return false;
}
// Read the immediate value
ushort imm16 = Decoder.ReadUInt16();
// Create the immediate operand
var immOperand = OperandFactory.CreateImmediateOperand(imm16, 16);
// Set the structured operands
instruction.StructuredOperands =
[
immOperand
];
return true;
}
}