-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Movsx() and Movzx() + Tests (#370)
* 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
Showing
5 changed files
with
482 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.