From 9cad5ff95c33a74c8801cc71a4d6c2abf32bd558 Mon Sep 17 00:00:00 2001 From: bird_egop Date: Sun, 13 Apr 2025 01:11:45 +0300 Subject: [PATCH] fixup --- .../X86/Handlers/Call/CallRm32Handler.cs | 2 +- .../X86/Handlers/Cmp/CmpImmWithRm8Handler.cs | 2 +- X86DisassemblerTests/CmpImmWithRm8Tests.cs | 49 +++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 X86DisassemblerTests/CmpImmWithRm8Tests.cs diff --git a/X86Disassembler/X86/Handlers/Call/CallRm32Handler.cs b/X86Disassembler/X86/Handlers/Call/CallRm32Handler.cs index 6541980..a5807d7 100644 --- a/X86Disassembler/X86/Handlers/Call/CallRm32Handler.cs +++ b/X86Disassembler/X86/Handlers/Call/CallRm32Handler.cs @@ -1,4 +1,4 @@ -namespace X86Disassembler.X86.Handlers.Group5; +namespace X86Disassembler.X86.Handlers.Call; /// /// Handler for CALL r/m32 instruction (0xFF /2) diff --git a/X86Disassembler/X86/Handlers/Cmp/CmpImmWithRm8Handler.cs b/X86Disassembler/X86/Handlers/Cmp/CmpImmWithRm8Handler.cs index 2cd59f8..fe44e21 100644 --- a/X86Disassembler/X86/Handlers/Cmp/CmpImmWithRm8Handler.cs +++ b/X86Disassembler/X86/Handlers/Cmp/CmpImmWithRm8Handler.cs @@ -1,4 +1,4 @@ -namespace X86Disassembler.X86.Handlers.Group1; +namespace X86Disassembler.X86.Handlers.Cmp; /// /// Handler for CMP r/m8, imm8 instruction (0x80 /7) diff --git a/X86DisassemblerTests/CmpImmWithRm8Tests.cs b/X86DisassemblerTests/CmpImmWithRm8Tests.cs new file mode 100644 index 0000000..b69c255 --- /dev/null +++ b/X86DisassemblerTests/CmpImmWithRm8Tests.cs @@ -0,0 +1,49 @@ +namespace X86DisassemblerTests; + +using System; +using Xunit; +using X86Disassembler.X86; + +/// +/// Tests for CMP r/m8, imm8 instruction (0x80 /7) +/// +public class CmpImmWithRm8Tests +{ + /// + /// Tests the CMP r8, imm8 instruction (0x80 /7) with register operand + /// + [Fact] + public void TestCmpR8Imm8() + { + // Arrange + byte[] code = { 0x80, 0xF9, 0x02 }; // CMP CL, 0x02 + + // Act + Disassembler disassembler = new Disassembler(code, 0x1000); + var instructions = disassembler.Disassemble(); + + // Assert + Assert.Single(instructions); + Assert.Equal("cmp", instructions[0].Mnemonic); + Assert.Equal("cl, 0x02", instructions[0].Operands); + } + + /// + /// Tests the CMP m8, imm8 instruction (0x80 /7) with memory operand + /// + [Fact] + public void TestCmpM8Imm8() + { + // Arrange + byte[] code = { 0x80, 0x39, 0x05 }; // CMP BYTE PTR [ECX], 0x05 + + // Act + Disassembler disassembler = new Disassembler(code, 0x1000); + var instructions = disassembler.Disassemble(); + + // Assert + Assert.Single(instructions); + Assert.Equal("cmp", instructions[0].Mnemonic); + Assert.Equal("byte ptr [ecx], 0x05", instructions[0].Operands); + } +}