2025-04-14 22:08:50 +03:00
|
|
|
using X86Disassembler.X86.Operands;
|
|
|
|
|
2025-04-13 18:22:44 +03:00
|
|
|
namespace X86Disassembler.X86.Handlers.Sub;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Handler for SUB r/m8, r8 instruction (0x28)
|
|
|
|
/// </summary>
|
|
|
|
public class SubRm8R8Handler : InstructionHandler
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the SubRm8R8Handler class
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
2025-04-14 22:08:50 +03:00
|
|
|
public SubRm8R8Handler(InstructionDecoder decoder)
|
|
|
|
: base(decoder)
|
2025-04-13 18:22:44 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks if this handler can decode the given opcode
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="opcode">The opcode to check</param>
|
|
|
|
/// <returns>True if this handler can decode the opcode</returns>
|
|
|
|
public override bool CanHandle(byte opcode)
|
|
|
|
{
|
|
|
|
return opcode == 0x28;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Decodes a SUB r/m8, r8 instruction
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="opcode">The opcode of the instruction</param>
|
|
|
|
/// <param name="instruction">The instruction object to populate</param>
|
|
|
|
/// <returns>True if the instruction was successfully decoded</returns>
|
|
|
|
public override bool Decode(byte opcode, Instruction instruction)
|
|
|
|
{
|
2025-04-14 22:08:50 +03:00
|
|
|
// Set the instruction type
|
|
|
|
instruction.Type = InstructionType.Sub;
|
2025-04-15 02:29:32 +03:00
|
|
|
|
|
|
|
// Read the ModR/M byte, specifying that we're dealing with 8-bit operands
|
2025-04-15 02:42:47 +03:00
|
|
|
var (_, reg, _, destinationOperand) = ModRMDecoder.ReadModRM8();
|
2025-04-14 22:08:50 +03:00
|
|
|
|
|
|
|
// Ensure the destination operand has the correct size (8-bit)
|
|
|
|
destinationOperand.Size = 8;
|
|
|
|
|
2025-04-16 01:10:33 +03:00
|
|
|
// Create the source register operand using the 8-bit register type
|
|
|
|
var sourceOperand = OperandFactory.CreateRegisterOperand8(reg);
|
2025-04-14 22:08:50 +03:00
|
|
|
|
|
|
|
// Set the structured operands
|
|
|
|
instruction.StructuredOperands =
|
|
|
|
[
|
|
|
|
destinationOperand,
|
|
|
|
sourceOperand
|
|
|
|
];
|
2025-04-13 18:22:44 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|