mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 08:18:36 +03:00
nice big refactor
This commit is contained in:
@ -11,11 +11,11 @@ public class PushImm32Handler : InstructionHandler
|
||||
/// <param name="codeBuffer">The buffer containing the code to decode</param>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
/// <param name="length">The length of the buffer</param>
|
||||
public PushImm32Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
public PushImm32Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
@ -25,7 +25,7 @@ public class PushImm32Handler : InstructionHandler
|
||||
{
|
||||
return opcode == 0x68;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a PUSH imm32 instruction
|
||||
/// </summary>
|
||||
@ -36,17 +36,13 @@ public class PushImm32Handler : InstructionHandler
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "push";
|
||||
|
||||
|
||||
// Read the immediate value
|
||||
uint imm32 = Decoder.ReadUInt32();
|
||||
if (Decoder.GetPosition() > Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Set the operands with 8-digit padding to match test expectations
|
||||
instruction.Operands = $"0x{imm32:X8}";
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -11,11 +11,11 @@ public class PushImm8Handler : InstructionHandler
|
||||
/// <param name="codeBuffer">The buffer containing the code to decode</param>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
/// <param name="length">The length of the buffer</param>
|
||||
public PushImm8Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
public PushImm8Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
@ -25,7 +25,7 @@ public class PushImm8Handler : InstructionHandler
|
||||
{
|
||||
return opcode == 0x6A;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a PUSH imm8 instruction
|
||||
/// </summary>
|
||||
@ -36,17 +36,13 @@ public class PushImm8Handler : InstructionHandler
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "push";
|
||||
|
||||
|
||||
// Read the immediate value
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
if (Decoder.GetPosition() > Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"0x{imm8:X2}";
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -11,11 +11,11 @@ public class PushRegHandler : InstructionHandler
|
||||
/// <param name="codeBuffer">The buffer containing the code to decode</param>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
/// <param name="length">The length of the buffer</param>
|
||||
public PushRegHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
public PushRegHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
@ -25,7 +25,7 @@ public class PushRegHandler : InstructionHandler
|
||||
{
|
||||
return opcode >= 0x50 && opcode <= 0x57;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a PUSH r32 instruction
|
||||
/// </summary>
|
||||
@ -36,14 +36,14 @@ public class PushRegHandler : InstructionHandler
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "push";
|
||||
|
||||
|
||||
// Register is encoded in the low 3 bits of the opcode
|
||||
int reg = opcode & 0x07;
|
||||
RegisterIndex reg = (RegisterIndex) (opcode & 0x07);
|
||||
string regName = ModRMDecoder.GetRegisterName(reg, 32);
|
||||
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = regName;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -42,16 +42,10 @@ public class PushRm32Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// 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, destOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// PUSH r/m32 is encoded as FF /6
|
||||
if (reg != 6)
|
||||
if (reg != RegisterIndex.Sp)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -62,12 +56,11 @@ public class PushRm32Handler : InstructionHandler
|
||||
// For memory operands, set the operand
|
||||
if (mod != 3) // Memory operand
|
||||
{
|
||||
string operand = ModRMDecoder.DecodeModRM(mod, rm, false);
|
||||
instruction.Operands = operand;
|
||||
instruction.Operands = destOperand;
|
||||
}
|
||||
else // Register operand
|
||||
{
|
||||
string rmName = GetRegister32(rm);
|
||||
string rmName = ModRMDecoder.GetRegisterName(rm, 32);
|
||||
instruction.Operands = rmName;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user