diff --git a/ParkanPlayground.sln.DotSettings.user b/ParkanPlayground.sln.DotSettings.user
index 7d73feb..b887de1 100644
--- a/ParkanPlayground.sln.DotSettings.user
+++ b/ParkanPlayground.sln.DotSettings.user
@@ -13,6 +13,9 @@
ForceIncluded
ForceIncluded
C:\Users\Admin\AppData\Local\JetBrains\Rider2024.3\resharper-host\temp\Rider\vAny\CoverageData\_ParkanPlayground.1073341822\Snapshot\snapshot.utdcvr
+ <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from <X86DisassemblerTests>" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
+ <Project Location="C:\Projects\CSharp\ParkanPlayground\X86DisassemblerTests" Presentation="<X86DisassemblerTests>" />
+</SessionState>
<SessionState ContinuousTestingMode="0" IsActive="True" Name="Session" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
<And>
@@ -20,7 +23,5 @@
<Project Location="C:\Projects\CSharp\ParkanPlayground\X86DisassemblerTests" Presentation="<X86DisassemblerTests>" />
</And>
</SessionState>
- <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from <X86DisassemblerTests>" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
- <Project Location="C:\Projects\CSharp\ParkanPlayground\X86DisassemblerTests" Presentation="<X86DisassemblerTests>" />
-</SessionState>
+
\ No newline at end of file
diff --git a/X86Disassembler/X86/Handlers/Xor/XorImmWithRm16SignExtendedHandler.cs b/X86Disassembler/X86/Handlers/Xor/XorImmWithRm16SignExtendedHandler.cs
index 3e09f6e..1524d40 100644
--- a/X86Disassembler/X86/Handlers/Xor/XorImmWithRm16SignExtendedHandler.cs
+++ b/X86Disassembler/X86/Handlers/Xor/XorImmWithRm16SignExtendedHandler.cs
@@ -67,10 +67,8 @@ public class XorImmWithRm16SignExtendedHandler : InstructionHandler
return false;
}
- // Read the immediate value and sign-extend it
- byte imm8 = Decoder.ReadByte();
- // Sign-extend to 16 bits by converting to sbyte first
- short imm16 = (short)((sbyte)imm8);
+ // Read the immediate value and sign-extend it to 16 bits
+ short imm16 = (sbyte)Decoder.ReadByte();
// Format the immediate value
string immStr = $"0x{(ushort)imm16:X4}";
diff --git a/X86Disassembler/X86/Handlers/Xor/XorImmWithRm32SignExtendedHandler.cs b/X86Disassembler/X86/Handlers/Xor/XorImmWithRm32SignExtendedHandler.cs
index 716d697..eb9379b 100644
--- a/X86Disassembler/X86/Handlers/Xor/XorImmWithRm32SignExtendedHandler.cs
+++ b/X86Disassembler/X86/Handlers/Xor/XorImmWithRm32SignExtendedHandler.cs
@@ -67,10 +67,8 @@ public class XorImmWithRm32SignExtendedHandler : InstructionHandler
return false;
}
- // Read the immediate value and sign-extend it
- byte imm8 = Decoder.ReadByte();
- // Sign-extend to 32 bits by converting to sbyte first
- int imm32 = (int)((sbyte)imm8);
+ // Read the immediate value and sign-extend it to 32 bits
+ int imm32 = (sbyte)Decoder.ReadByte();
// Format the immediate value
string immStr;
@@ -79,15 +77,10 @@ public class XorImmWithRm32SignExtendedHandler : InstructionHandler
// For negative values, show the full sign-extended 32-bit value
immStr = $"0x{imm32:X8}";
}
- else if (imm8 == 0)
- {
- // For zero, use the expected format
- immStr = "0x00";
- }
else
{
// For positive values, show without leading zeros
- immStr = $"0x{imm8:X}";
+ immStr = $"0x{imm32:X2}";
}
// Set the operands
diff --git a/X86Disassembler/X86/Handlers/Xor/XorImmWithRm8Handler.cs b/X86Disassembler/X86/Handlers/Xor/XorImmWithRm8Handler.cs
index 43d8d7a..6ae2b6c 100644
--- a/X86Disassembler/X86/Handlers/Xor/XorImmWithRm8Handler.cs
+++ b/X86Disassembler/X86/Handlers/Xor/XorImmWithRm8Handler.cs
@@ -68,8 +68,7 @@ public class XorImmWithRm8Handler : InstructionHandler
}
// Read the immediate value
- byte imm8 = CodeBuffer[position];
- Decoder.SetPosition(position + 1);
+ byte imm8 = Decoder.ReadByte();
// Format the immediate value
string immStr = $"0x{imm8:X2}";
diff --git a/X86Disassembler/X86/Handlers/Xor/XorMemRegHandler.cs b/X86Disassembler/X86/Handlers/Xor/XorMemRegHandler.cs
index 2dea822..ec28eca 100644
--- a/X86Disassembler/X86/Handlers/Xor/XorMemRegHandler.cs
+++ b/X86Disassembler/X86/Handlers/Xor/XorMemRegHandler.cs
@@ -45,17 +45,8 @@ public class XorMemRegHandler : 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);
-
- // Decode the destination operand
- string destOperand = ModRMDecoder.DecodeModRM(mod, rm, false);
-
+ var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
+
// Get the source register
string srcReg = GetRegister32(reg);
diff --git a/X86Disassembler/X86/Handlers/Xor/XorRegMemHandler.cs b/X86Disassembler/X86/Handlers/Xor/XorRegMemHandler.cs
index 183297d..80eda63 100644
--- a/X86Disassembler/X86/Handlers/Xor/XorRegMemHandler.cs
+++ b/X86Disassembler/X86/Handlers/Xor/XorRegMemHandler.cs
@@ -45,17 +45,8 @@ public class XorRegMemHandler : 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);
-
- // Decode the source operand
- string srcOperand = ModRMDecoder.DecodeModRM(mod, rm, false);
-
+ var (mod, reg, rm, srcOperand) = ModRMDecoder.ReadModRM();
+
// Get the destination register
string destReg = GetRegister32(reg);
diff --git a/X86DisassemblerTests/InstructionTests/Group1InstructionTests.cs b/X86DisassemblerTests/InstructionTests/Group1InstructionTests.cs
index dd2b9ee..c318626 100644
--- a/X86DisassemblerTests/InstructionTests/Group1InstructionTests.cs
+++ b/X86DisassemblerTests/InstructionTests/Group1InstructionTests.cs
@@ -281,6 +281,6 @@ public class Group1InstructionTests
// Assert
Assert.NotNull(instruction);
Assert.Equal("xor", instruction.Mnemonic);
- Assert.Equal("esi, 0x00000042", instruction.Operands);
+ Assert.Equal("esi, 0x42", instruction.Operands);
}
}