Skip to content

Commit

Permalink
Add Movsx() and Movzx() + Tests (#370)
Browse files Browse the repository at this point in the history
* First attempt fail

* Update logic

* Cleanup

* changed to uint

* Fixes

* Fix

* Add Movzx() and tests

* Update tests

* Fix MOVSX tests, extension

* Refactor extensions to remove hardcodes

* typo

* Address Feedback

* Updated to use cast
  • Loading branch information
tuday2 committed Jan 12, 2021
1 parent 1c14b0c commit cbf36e9
Show file tree
Hide file tree
Showing 5 changed files with 482 additions and 3 deletions.
150 changes: 150 additions & 0 deletions MBBSEmu.Tests/CPU/MOVSX_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
using Iced.Intel;
using Xunit;
using static Iced.Intel.AssemblerRegisters;

namespace MBBSEmu.Tests.CPU
{
public class MOVSX_Tests : CpuTestBase
{
[Theory]
[InlineData(0xC3EE, 0xFFFFC3EE)]
[InlineData(0xFFFF, 0xFFFFFFFF)]
[InlineData(0x0FFF, 0x00000FFF)]
[InlineData(0xFFF4, 0xFFFFFFF4)]
public void MOVSX_R32_M16(ushort esValue, uint expectedResult)
{
Reset();

mbbsEmuMemoryCore.AddSegment(2);
mbbsEmuCpuRegisters.DS = 2;
mbbsEmuMemoryCore.SetWord(2, 0, esValue);

var instructions = new Assembler(16);
instructions.movsx(eax, __word_ptr[0]);
CreateCodeSegment(instructions);

//Process Instruction
mbbsEmuCpuCore.Tick();

//Verify Results
Assert.Equal(expectedResult, mbbsEmuCpuRegisters.EAX);
}

[Theory]
[InlineData(0xC3EE, 0xFFFFC3EE)]
[InlineData(0xFFFF, 0xFFFFFFFF)]
[InlineData(0x0FFF, 0x00000FFF)]
[InlineData(0xFFF4, 0xFFFFFFF4)]
public void MOVSX_R32_R16(ushort bxValue, uint expectedResult)
{
Reset();

mbbsEmuCpuRegisters.BX = bxValue;

var instructions = new Assembler(16);
instructions.movsx(ebx, bx);
CreateCodeSegment(instructions);

//Process Instruction
mbbsEmuCpuCore.Tick();

//Verify Results
Assert.Equal(expectedResult, mbbsEmuCpuRegisters.EBX);
}

[Theory]
[InlineData(0xC3, 0xFFFFFFC3)]
[InlineData(0xFF, 0xFFFFFFFF)]
[InlineData(0x0F, 0x0000000F)]
[InlineData(0xF4, 0xFFFFFFF4)]
[InlineData(0x80, 0xFFFFFF80)]
public void MOVSX_R32_M8(byte dsValue, uint expectedResult)
{
Reset();

mbbsEmuMemoryCore.AddSegment(2);
mbbsEmuCpuRegisters.DS = 2;
mbbsEmuMemoryCore.SetByte(2, 0, dsValue);

var instructions = new Assembler(16);
instructions.movsx(eax, __byte_ptr[0]);
CreateCodeSegment(instructions);

//Process Instruction
mbbsEmuCpuCore.Tick();

//Verify Results
Assert.Equal(expectedResult, mbbsEmuCpuRegisters.EAX);
}

[Theory]
[InlineData(0xC3, 0xFFFFFFC3)]
[InlineData(0xFF, 0xFFFFFFFF)]
[InlineData(0x0F, 0x0000000F)]
[InlineData(0xF4, 0xFFFFFFF4)]
public void MOVSX_R32_R8(byte blValue, uint expectedResult)
{
Reset();

mbbsEmuCpuRegisters.BL = blValue;

var instructions = new Assembler(16);
instructions.movsx(ebx, bl);
CreateCodeSegment(instructions);

//Process Instruction
mbbsEmuCpuCore.Tick();

//Verify Results
Assert.Equal(expectedResult, mbbsEmuCpuRegisters.EBX);
}

[Theory]
[InlineData(0x80, 0xFF80)]
[InlineData(0xFF, 0xFFFF)]
[InlineData(0x8C, 0xFF8C)]
[InlineData(0x60, 0x0060)]
[InlineData(0x0F, 0x000F)]
public void MOVSX_R16_M8(byte dsValue, ushort expectedResult)
{
Reset();

mbbsEmuMemoryCore.AddSegment(2);
mbbsEmuCpuRegisters.DS = 2;
mbbsEmuMemoryCore.SetByte(2, 0, dsValue);

var instructions = new Assembler(16);
instructions.movsx(dx, __byte_ptr[0]);
CreateCodeSegment(instructions);

//Process Instruction
mbbsEmuCpuCore.Tick();

//Verify Results
Assert.Equal(expectedResult, mbbsEmuCpuRegisters.DX);
}

[Theory]
[InlineData(0x80, 0xFF80)]
[InlineData(0xFF, 0xFFFF)]
[InlineData(0x8C, 0xFF8C)]
[InlineData(0x60, 0x0060)]
[InlineData(0x0F, 0x000F)]
public void MOVSX_R16_R8(byte blValue, ushort expectedResult)
{
Reset();

mbbsEmuCpuRegisters.BL = blValue;

var instructions = new Assembler(16);
instructions.movsx(dx, bl);
CreateCodeSegment(instructions);

//Process Instruction
mbbsEmuCpuCore.Tick();

//Verify Results
Assert.Equal(expectedResult, mbbsEmuCpuRegisters.DX);
}
}
}
147 changes: 147 additions & 0 deletions MBBSEmu.Tests/CPU/MOVZX_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
using Iced.Intel;
using Xunit;
using static Iced.Intel.AssemblerRegisters;

namespace MBBSEmu.Tests.CPU
{
public class MOVZX_Tests : CpuTestBase
{
[Theory]
[InlineData(0xC3EE, 0x0000C3EE)]
[InlineData(0xFFFF, 0x0000FFFF)]
[InlineData(0x0FFF, 0x00000FFF)]
[InlineData(0xFFF4, 0x0000FFF4)]
public void MOVZX_R32_M16(ushort dsValue, uint expectedResult)
{
Reset();

mbbsEmuMemoryCore.AddSegment(2);
mbbsEmuCpuRegisters.DS = 2;
mbbsEmuMemoryCore.SetWord(2, 0, dsValue);

var instructions = new Assembler(16);
instructions.movzx(eax, __word_ptr[0]);
CreateCodeSegment(instructions);

//Process Instruction
mbbsEmuCpuCore.Tick();

//Verify Results
Assert.Equal(expectedResult, mbbsEmuCpuRegisters.EAX);
}

[Theory]
[InlineData(0xC3EE, 0x0000C3EE)]
[InlineData(0xFFFF, 0x0000FFFF)]
[InlineData(0x0FFF, 0x00000FFF)]
[InlineData(0xFFF4, 0x0000FFF4)]
public void MOVZX_R32_R16(ushort bxValue, uint expectedResult)
{
Reset();

mbbsEmuCpuRegisters.BX = bxValue;

var instructions = new Assembler(16);
instructions.movzx(ebx, bx);
CreateCodeSegment(instructions);

//Process Instruction
mbbsEmuCpuCore.Tick();

//Verify Results
Assert.Equal(expectedResult, mbbsEmuCpuRegisters.EBX);
}

[Theory]
[InlineData(0xC3, 0x000000C3)]
[InlineData(0xFF, 0x000000FF)]
[InlineData(0x0F, 0x0000000F)]
[InlineData(0xF4, 0x000000F4)]
public void MOVZX_R32_M8(byte dsValue, uint expectedResult)
{
Reset();

mbbsEmuMemoryCore.AddSegment(2);
mbbsEmuCpuRegisters.DS = 2;
mbbsEmuMemoryCore.SetByte(2, 0, dsValue);

var instructions = new Assembler(16);
instructions.movzx(eax, __byte_ptr[0]);
CreateCodeSegment(instructions);

//Process Instruction
mbbsEmuCpuCore.Tick();

//Verify Results
Assert.Equal(expectedResult, mbbsEmuCpuRegisters.EAX);
}

[Theory]
[InlineData(0xC3, 0x000000C3)]
[InlineData(0xFF, 0x000000FF)]
[InlineData(0x0F, 0x0000000F)]
[InlineData(0xF4, 0x000000F4)]
public void MOVZX_R32_R8(byte blValue, uint expectedResult)
{
Reset();

mbbsEmuCpuRegisters.BL = blValue;

var instructions = new Assembler(16);
instructions.movzx(ebx, bl);
CreateCodeSegment(instructions);

//Process Instruction
mbbsEmuCpuCore.Tick();

//Verify Results
Assert.Equal(expectedResult, mbbsEmuCpuRegisters.EBX);
}

[Theory]
[InlineData(0xC3, 0x00C3)]
[InlineData(0xFF, 0x00FF)]
[InlineData(0x0F, 0x000F)]
[InlineData(0xF4, 0x00F4)]
public void MOVZX_R16_M8(byte dsValue, ushort expectedResult)
{
Reset();

mbbsEmuMemoryCore.AddSegment(2);
mbbsEmuCpuRegisters.DS = 2;
mbbsEmuMemoryCore.SetByte(2, 0, dsValue);

var instructions = new Assembler(16);
instructions.movzx(bx, __byte_ptr[0]);
CreateCodeSegment(instructions);

//Process Instruction
mbbsEmuCpuCore.Tick();

//Verify Results
Assert.Equal(expectedResult, mbbsEmuCpuRegisters.BX);
}

[Theory]
[InlineData(0x40, 0x0040)]
[InlineData(0xF8, 0x00F8)]
[InlineData(0x0F, 0x000F)]
[InlineData(0xF4, 0x00F4)]
public void MOVZX_R16_R8(byte blValue, ushort expectedResult)
{
Reset();

mbbsEmuCpuRegisters.BL = blValue;

var instructions = new Assembler(16);
instructions.movzx(bx, bl);
CreateCodeSegment(instructions);

//Process Instruction
mbbsEmuCpuCore.Tick();

//Verify Results
Assert.Equal(expectedResult, mbbsEmuCpuRegisters.BX);
}
}
}
Loading

0 comments on commit cbf36e9

Please sign in to comment.