-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fixes 3 Operand IMUL Operations - Unit Tests for IMUL
- Loading branch information
Showing
3 changed files
with
116 additions
and
5 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,113 @@ | ||
using Iced.Intel; | ||
using Xunit; | ||
using static Iced.Intel.AssemblerRegisters; | ||
|
||
namespace MBBSEmu.Tests.CPU | ||
{ | ||
public class IMUL_Tests : CpuTestBase | ||
{ | ||
[Theory] | ||
[InlineData(1, -1, -1, false, false)] | ||
[InlineData(-1, -1, 1, false, false)] | ||
[InlineData(-127, -1, 127, false, false)] | ||
[InlineData(127, -1, -127, false, false)] | ||
public void IMUL_8_R8_Test(sbyte alValue, sbyte valueToMultiply, short expectedValue, bool carryFlag, | ||
bool overflowFlag) | ||
{ | ||
Reset(); | ||
mbbsEmuCpuRegisters.AL = (byte)alValue; | ||
mbbsEmuCpuRegisters.BL = (byte)valueToMultiply; | ||
|
||
var instructions = new Assembler(16); | ||
instructions.imul(bl); | ||
CreateCodeSegment(instructions); | ||
|
||
mbbsEmuCpuCore.Tick(); | ||
|
||
//Verify Results | ||
Assert.Equal(expectedValue, (sbyte)mbbsEmuCpuRegisters.AL); | ||
Assert.Equal(carryFlag, mbbsEmuCpuRegisters.CarryFlag); | ||
Assert.Equal(overflowFlag, mbbsEmuCpuRegisters.OverflowFlag); | ||
} | ||
|
||
[Theory] | ||
[InlineData(1, -1, -1, false, false)] | ||
[InlineData(-1, -1, 1, false, false)] | ||
[InlineData(-127, -1, 127, false, false)] | ||
[InlineData(127, -1, -127, false, false)] | ||
[InlineData(short.MaxValue, -1, short.MinValue + 1, false, false)] | ||
public void IMUL_16_R16_Test(short axValue, short valueToMultiply, short expectedValue, bool carryFlag, | ||
bool overflowFlag) | ||
{ | ||
Reset(); | ||
mbbsEmuCpuRegisters.AX = (ushort)axValue; | ||
mbbsEmuCpuRegisters.BX = (ushort)valueToMultiply; | ||
|
||
var instructions = new Assembler(16); | ||
instructions.imul(bx); | ||
CreateCodeSegment(instructions); | ||
|
||
mbbsEmuCpuCore.Tick(); | ||
|
||
//Verify Results | ||
Assert.Equal(expectedValue, (short)mbbsEmuCpuRegisters.AX); | ||
Assert.Equal(carryFlag, mbbsEmuCpuRegisters.CarryFlag); | ||
Assert.Equal(overflowFlag, mbbsEmuCpuRegisters.OverflowFlag); | ||
} | ||
|
||
|
||
[Theory] | ||
[InlineData(1, -1, -1, false, false)] | ||
[InlineData(-1, -1, 1, false, false)] | ||
[InlineData(-127, -1, 127, false, false)] | ||
[InlineData(127, -1, -127, false, false)] | ||
[InlineData(short.MaxValue, -1, short.MinValue + 1, false, false)] | ||
public void IMUL_16_R16_3OP_Test(short bxValue, short valueToMultiply, short expectedValue, bool carryFlag, | ||
bool overflowFlag) | ||
{ | ||
Reset(); | ||
mbbsEmuCpuRegisters.BX = (ushort)bxValue; | ||
|
||
var instructions = new Assembler(16); | ||
//AX = BX * ValueToMultiply | ||
instructions.imul(ax, bx, valueToMultiply); | ||
CreateCodeSegment(instructions); | ||
|
||
mbbsEmuCpuCore.Tick(); | ||
|
||
//Verify Results | ||
Assert.Equal(expectedValue, (short)mbbsEmuCpuRegisters.AX); | ||
Assert.Equal(carryFlag, mbbsEmuCpuRegisters.CarryFlag); | ||
Assert.Equal(overflowFlag, mbbsEmuCpuRegisters.OverflowFlag); | ||
} | ||
|
||
[Theory] | ||
[InlineData(1, -1, -1, false, false)] | ||
[InlineData(-1, -1, 1, false, false)] | ||
[InlineData(-127, -1, 127, false, false)] | ||
[InlineData(127, -1, -127, false, false)] | ||
[InlineData(short.MaxValue, -1, short.MinValue + 1, false, false)] | ||
public void IMUL_16_M16_3OP_Test(short memoryValue, short valueToMultiply, short expectedValue, bool carryFlag, | ||
bool overflowFlag) | ||
{ | ||
Reset(); | ||
|
||
//Setup Memory | ||
CreateDataSegment(new byte[ushort.MaxValue]); | ||
mbbsEmuMemoryCore.SetWord(2,0, (ushort)memoryValue); | ||
mbbsEmuCpuRegisters.DS = 2; | ||
|
||
var instructions = new Assembler(16); | ||
//AX == DS:[0] * ValueToMultiply | ||
instructions.imul(ax, __word_ptr[0], valueToMultiply); | ||
CreateCodeSegment(instructions); | ||
|
||
mbbsEmuCpuCore.Tick(); | ||
|
||
//Verify Results | ||
Assert.Equal(expectedValue, (short)mbbsEmuCpuRegisters.AX); | ||
Assert.Equal(carryFlag, mbbsEmuCpuRegisters.CarryFlag); | ||
Assert.Equal(overflowFlag, mbbsEmuCpuRegisters.OverflowFlag); | ||
} | ||
} | ||
} |
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
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