diff --git a/X86Disassembler/X86/ModRMDecoder.cs b/X86Disassembler/X86/ModRMDecoder.cs index 0a4f6d4..3f6ee08 100644 --- a/X86Disassembler/X86/ModRMDecoder.cs +++ b/X86Disassembler/X86/ModRMDecoder.cs @@ -403,7 +403,9 @@ public class ModRMDecoder else // Memory operand { // For memory operands, we need to map the RegisterIndex8 to RegisterIndex for base registers - RegisterIndex rmRegIndex = MapRegister8ToBaseRegister(rm); + // The rmIndex is the raw value from the ModR/M byte, not the mapped RegisterIndex8 + // This is important because we need to check if it's 4 (ESP) for SIB byte + RegisterIndex rmRegIndex = MapModRMToRegisterIndex(rmIndex); // Use the DecodeModRM8 method to get an 8-bit memory operand operand = DecodeModRM8(mod, rmRegIndex); diff --git a/X86DisassemblerTests/InstructionTests/OrRm8R8HandlerTests.cs b/X86DisassemblerTests/InstructionTests/OrRm8R8HandlerTests.cs index 3712408..25e0a27 100644 --- a/X86DisassemblerTests/InstructionTests/OrRm8R8HandlerTests.cs +++ b/X86DisassemblerTests/InstructionTests/OrRm8R8HandlerTests.cs @@ -43,10 +43,10 @@ public class OrRm8R8HandlerTests // Check the second operand (AL) var alOperand = instruction.StructuredOperands[1]; - Assert.IsType(alOperand); - var registerOperand = (RegisterOperand)alOperand; - Assert.Equal(RegisterIndex.A, registerOperand.Register); - Assert.Equal(8, registerOperand.Size); // Validate that it's an 8-bit register (AL) + Assert.IsType(alOperand); + var register8Operand = (Register8Operand)alOperand; + Assert.Equal(RegisterIndex8.AL, register8Operand.Register); + Assert.Equal(8, register8Operand.Size); // Validate that it's an 8-bit register (AL) } ///