0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-08-07 03:16:39 +03:00

Refactor SUB handlers

This commit is contained in:
bird_egop
2025-04-13 18:22:44 +03:00
parent a04a16af7d
commit e91a0223f7
18 changed files with 493 additions and 200 deletions

View File

@@ -37,26 +37,20 @@ public class SubR16Rm16Handler : InstructionHandler
{
// Set the mnemonic
instruction.Mnemonic = "sub";
int position = Decoder.GetPosition();
if (position >= Length)
{
return false;
}
// Read the ModR/M byte
byte modRM = CodeBuffer[position++];
Decoder.SetPosition(position);
// Extract the fields from the ModR/M byte
byte mod = (byte)((modRM & 0xC0) >> 6);
byte reg = (byte)((modRM & 0x38) >> 3);
byte rm = (byte)(modRM & 0x07);
var (mod, reg, rm, memOperand) = ModRMDecoder.ReadModRM();
// Get register name (16-bit)
string regName = ModRMDecoder.GetRegisterName(reg, 16);
// For mod == 3, both operands are registers
if (mod == 3)
{
@@ -65,15 +59,12 @@ public class SubR16Rm16Handler : InstructionHandler
}
else // Memory operand
{
// Get the memory operand string (use false for is64Bit)
string memOperand = ModRMDecoder.DecodeModRM(mod, rm, false);
// Replace "dword" with "word" in the memory operand
memOperand = memOperand.Replace("dword", "word");
instruction.Operands = $"{regName}, {memOperand}";
}
return true;
}
}
}