This commit is contained in:
mterwoord_cp 2008-11-10 11:20:38 +00:00
parent a0163de71d
commit 9032d256cb
7 changed files with 51 additions and 26 deletions

View file

@ -59,5 +59,18 @@ namespace Indy.IL2CPU.Tests.Assembler.X86 {
new Move { Size = 8, DestinationReg = Registers.EBP, DestinationIsIndirect = true, SourceValue = 72 };
Verify();
}
[Test]
public void TestImmediateToMemorySimple16() {
new Move { Size = 16, DestinationReg = Registers.EAX, DestinationIsIndirect = true, SourceValue = 65 };
new Move { Size = 16, DestinationReg = Registers.EBX, DestinationIsIndirect = true, SourceValue = 66 };
new Move { Size = 16, DestinationReg = Registers.ECX, DestinationIsIndirect = true, SourceValue = 67 };
new Move { Size = 16, DestinationReg = Registers.EDX, DestinationIsIndirect = true, SourceValue = 68 };
new Move { Size = 16, DestinationReg = Registers.EDI, DestinationIsIndirect = true, SourceValue = 69 };
new Move { Size = 16, DestinationReg = Registers.ESI, DestinationIsIndirect = true, SourceValue = 70 };
new Move { Size = 16, DestinationReg = Registers.ESP, DestinationIsIndirect = true, SourceValue = 71 };
new Move { Size = 16, DestinationReg = Registers.EBP, DestinationIsIndirect = true, SourceValue = 72 };
Verify();
}
}
}

View file

@ -0,0 +1,10 @@
use32
org 0x200000
mov word [EAX], 0x41
mov word [EBX], 0x42
mov word [ECX], 0x43
mov word [EDX], 0x44
mov word [EDI], 0x45
mov word [ESI], 0x46
mov word [ESP], 0x47
mov word [EBP], 0x48

View file

@ -79,6 +79,12 @@
<ItemGroup>
<EmbeddedResource Include="Assembler\X86\VerificationData\MoveTests\ImmediateToRegister8.asm" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Assembler\X86\VerificationData\MoveTests\ImmediateToMemorySimple16.asm" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Assembler\X86\VerificationData\MoveTests\ImmediateToMemorySimple16.bin" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View file

@ -18,26 +18,18 @@ namespace Indy.IL2CPU.Assembler.X86 {
DestinationRegByte = 0,
SourceImmediate = true
}); // immediate to register
//aData.EncodingOptions.Add(new InstructionData.InstructionEncodingOption {
// OpCode = new byte[] { 0xC6 },
// //NeedsModRMByte=true,
// //OperandSize=InstructionSize.Word,
// AllowedSizes=InstructionSizes.Word,
// OperandSizeByte = 0,
// OperandSizeBitShiftLeft = 0,
// SourceImmediate = true
//}); // immediate to memory
aData.EncodingOptions.Add(new InstructionData.InstructionEncodingOption {
OpCode = new byte[] { 0xC6 },
NeedsModRMByte=true,
NeedsModRMByte = true,
AllowedSizes = InstructionSizes.Word,
OperandSizeByte = 0,
OperandSizeBitShiftLeft = 0,
SourceImmediate = true,
DestinationRegByte=1,
DestinationMemory = true
DestinationRegByte = 1,
DestinationMemory = true,
DestinationReg=Registers.ESP
}); // immediate to memory
}
}
}

View file

@ -317,6 +317,9 @@ namespace Indy.IL2CPU.Assembler.X86 {
private static byte[] GetData(Indy.IL2CPU.Assembler.Assembler aAssembler, InstructionWithDestinationAndSourceAndSize aInstruction, InstructionData aInstructionData) {
var xEncodingOption = GetInstructionEncodingOption(aInstruction, aInstructionData);
if(aInstruction.ToString() == "mov word [ESP], 0x47") {
Console.Write("");
}
ulong xSize = 0;
Instruction.DetermineSize(aInstruction, aInstructionData, out xSize);
if(xSize==0) {
@ -338,7 +341,7 @@ namespace Indy.IL2CPU.Assembler.X86 {
Array.Copy(xEncodingOption.OpCode, 0, xBuffer, xExtraOffset, xEncodingOption.OpCode.Length);
byte? xSIB = null;
if (xEncodingOption.NeedsModRMByte) {
xBuffer[xEncodingOption.OpCode.Length] = EncodeModRMByte(aInstruction.DestinationReg, aInstruction.DestinationIsIndirect, aInstruction.DestinationDisplacement > 0, aInstruction.DestinationDisplacement > 255, out xSIB);
xBuffer[xEncodingOption.OpCode.Length + xExtraOffset] = EncodeModRMByte(aInstruction.DestinationReg, aInstruction.DestinationIsIndirect, aInstruction.DestinationDisplacement > 0, aInstruction.DestinationDisplacement > 255, out xSIB);
//byte
// = EncodeModRMByte()
//if(aInstruction.DestinationReg != Guid.Empty && !aInstruction.DestinationIsIndirect) {
@ -349,11 +352,11 @@ namespace Indy.IL2CPU.Assembler.X86 {
//}
// todo: add more ModRM stuff
}
if (aInstruction.DestinationReg != Guid.Empty) {
if (aInstruction.DestinationReg != Guid.Empty && !xEncodingOption.NeedsModRMByte) {
xBuffer[xEncodingOption.DestinationRegByte + xExtraOffset] |= (byte)(EncodeRegister(aInstruction.DestinationReg) << xEncodingOption.DestinationRegBitShiftLeft);
}
if(xSIB!=null) {
xBuffer[xEncodingOption.OpCode.Length + 1] = xSIB.Value;
xBuffer[xEncodingOption.OpCode.Length + xExtraOffset + 1] = xSIB.Value;
xExtraOffset++;
}
// todo: add more options
@ -366,7 +369,7 @@ namespace Indy.IL2CPU.Assembler.X86 {
}
if (xEncodingOption.OperandSizeByte.HasValue) {
if (aInstruction.Size > 8) {
xBuffer[xEncodingOption.OperandSizeByte.Value + xExtraOffset] |= (byte)(1 << xEncodingOption.OperandSizeBitShiftLeft);
xBuffer[xEncodingOption.OperandSizeByte.Value + xOpCodeOffset] |= (byte)(1 << xEncodingOption.OperandSizeBitShiftLeft);
}
}

View file

@ -1,4 +1,4 @@
//#define BINARY
#define BINARY
using System;
using System.Collections.Generic;
using System.Linq;
@ -12,14 +12,15 @@ namespace TestApp {
class Program {
class Renderer : Y86 {
public void DoRender() {
new Move { DestinationReg = Registers.AL, SourceValue = 1 };
new Move { DestinationReg = Registers.BL, SourceValue = 2 };
new Move { DestinationReg = Registers.CL, SourceValue = 3 };
new Move { DestinationReg = Registers.DL, SourceValue = 4 };
new Move { DestinationReg = Registers.AH, SourceValue = 1 };
new Move { DestinationReg = Registers.BH, SourceValue = 2 };
new Move { DestinationReg = Registers.CH, SourceValue = 3 };
new Move { DestinationReg = Registers.DH, SourceValue = 4 };
new Move { Size = 8, DestinationReg = Registers.EAX, DestinationIsIndirect = true, SourceValue = 65 };
new Move { Size = 8, DestinationReg = Registers.EBX, DestinationIsIndirect = true, SourceValue = 66 };
new Move { Size = 8, DestinationReg = Registers.ECX, DestinationIsIndirect = true, SourceValue = 67 };
new Move { Size = 8, DestinationReg = Registers.EDX, DestinationIsIndirect = true, SourceValue = 68 };
new Move { Size = 8, DestinationReg = Registers.EDI, DestinationIsIndirect = true, SourceValue = 69 };
new Move { Size = 8, DestinationReg = Registers.ESI, DestinationIsIndirect = true, SourceValue = 70 };
new Move { Size = 8, DestinationReg = Registers.ESP, DestinationIsIndirect = true, SourceValue = 71 };
new Move { Size = 8, DestinationReg = Registers.EBP, DestinationIsIndirect = true, SourceValue = 72 };
}
}
static void Main(string[] args) {