diff --git a/source/Indy.IL2CPU.Assembler.X86/Indy.IL2CPU.Assembler.X86.csproj b/source/Indy.IL2CPU.Assembler.X86/Indy.IL2CPU.Assembler.X86.csproj
index a93ea9236..38fe1ead2 100644
--- a/source/Indy.IL2CPU.Assembler.X86/Indy.IL2CPU.Assembler.X86.csproj
+++ b/source/Indy.IL2CPU.Assembler.X86/Indy.IL2CPU.Assembler.X86.csproj
@@ -70,6 +70,9 @@
+
+
+
diff --git a/source/Indy.IL2CPU.Assembler.X86/MoveAndSignExtend.cs b/source/Indy.IL2CPU.Assembler.X86/MoveAndSignExtend.cs
new file mode 100644
index 000000000..9024a28ee
--- /dev/null
+++ b/source/Indy.IL2CPU.Assembler.X86/MoveAndSignExtend.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Indy.IL2CPU.Assembler.X86
+{
+ [OpCode(0xFFFFFFFF, "movsx")]
+ public class MoveAndSignExtend : Instruction
+ {
+ private string mDest;
+ private string mSource;
+ public MoveAndSignExtend(string aDest, string aSource)
+ {
+ mDest = aDest;
+ mSource = aSource;
+ }
+ public override string ToString()
+ {
+ return string.Format("movsx {0}, {1}", mDest, mSource);
+ }
+ }
+}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.Assembler.X86/MoveAndZeroExtend.cs b/source/Indy.IL2CPU.Assembler.X86/MoveAndZeroExtend.cs
new file mode 100644
index 000000000..92fc115c7
--- /dev/null
+++ b/source/Indy.IL2CPU.Assembler.X86/MoveAndZeroExtend.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Indy.IL2CPU.Assembler.X86
+{
+ [OpCode(0xFFFFFFFF, "movzx")]
+ public class MoveAndZeroExtend : Instruction
+ {
+ private string mDest;
+ private string mSource;
+ public MoveAndZeroExtend(string aDest, string aSource)
+ {
+ mDest = aDest;
+ mSource = aSource;
+ }
+ public override string ToString()
+ {
+ return string.Format("movzx {0}, {1}", mDest, mSource);
+ }
+ }
+}
diff --git a/source/Indy.IL2CPU.Assembler.X86/SignExtendAX.cs b/source/Indy.IL2CPU.Assembler.X86/SignExtendAX.cs
new file mode 100644
index 000000000..8699c7c0b
--- /dev/null
+++ b/source/Indy.IL2CPU.Assembler.X86/SignExtendAX.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Indy.IL2CPU.Assembler.X86
+{
+ [OpCode(0xFFFFFFFF, "cdq")]
+ public class SignExtendAX : Instruction
+ {
+ private int mOldSize;
+ public SignExtendAX(int aOldSize)
+ {
+ mOldSize = aOldSize;
+ }
+ public override string ToString()
+ {
+ switch (mOldSize)
+ {
+ case 4:
+ return "cdq";
+ case 2:
+ return "cwd";
+ default:
+ throw new NotSupportedException();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Conv_I1.cs b/source/Indy.IL2CPU.IL.X86/Conv_I1.cs
index e369d12f3..81ffcf992 100644
--- a/source/Indy.IL2CPU.IL.X86/Conv_I1.cs
+++ b/source/Indy.IL2CPU.IL.X86/Conv_I1.cs
@@ -1,8 +1,8 @@
using System;
using System.IO;
-
-
-using CPU = Indy.IL2CPU.Assembler.X86;
+using CPU = Indy.IL2CPU.Assembler;
+using Indy.IL2CPU.Assembler;
+using CPUx86 = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(OpCodeEnum.Conv_I1)]
@@ -11,8 +11,32 @@ namespace Indy.IL2CPU.IL.X86 {
: base(aReader, aMethodInfo) {
}
public override void DoAssemble() {
- throw new Exception("Not supported!");
- // todo: implement correct truncating
+ StackContent xSource = Assembler.StackContents.Pop();
+ if (xSource.IsFloat)
+ {
+ throw new Exception("Floats not yet supported");
+ }
+ switch (xSource.Size)
+ {
+ case 1:
+ new CPUx86.Noop();
+ break;
+ case 2:
+ case 4:
+ new CPUx86.Pop("eax");
+ new CPUx86.MoveAndSignExtend("eax", "al");
+ new CPUx86.Push("eax");
+ break;
+ case 8:
+ new CPUx86.Pop(CPUx86.Registers.EAX);
+ new CPUx86.Pop("EBX");
+ new CPUx86.MoveAndSignExtend("eax", "al");
+ new CPUx86.Pushd(CPUx86.Registers.EAX);
+ break;
+ default:
+ throw new Exception("SourceSize " + xSource + " not supported!");
+ }
+ Assembler.StackContents.Push(new StackContent(1, true, false, true));
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Conv_I2.cs b/source/Indy.IL2CPU.IL.X86/Conv_I2.cs
index 63edd3cd2..a143a97f4 100644
--- a/source/Indy.IL2CPU.IL.X86/Conv_I2.cs
+++ b/source/Indy.IL2CPU.IL.X86/Conv_I2.cs
@@ -18,17 +18,19 @@ namespace Indy.IL2CPU.IL.X86 {
switch (xSource.Size) {
case 1:
case 2:
- case 4: {
- new CPUx86.Noop();
- break;
- }
- case 8: {
- new CPUx86.Pop(CPUx86.Registers.EAX);
- new CPUx86.Add("esp", "4");
- new CPUx86.Pushd(CPUx86.Registers.EAX);
- break;
-
- }
+ new CPUx86.Noop();
+ break;
+ case 4:
+ new CPUx86.Pop("eax");
+ new CPUx86.MoveAndSignExtend("eax", "ax");
+ new CPUx86.Push("eax");
+ break;
+ case 8:
+ new CPUx86.Pop(CPUx86.Registers.EAX);
+ new CPUx86.Pop("EBX");
+ new CPUx86.MoveAndSignExtend("eax", "ax");
+ new CPUx86.Pushd(CPUx86.Registers.EAX);
+ break;
default:
throw new Exception("SourceSize " + xSource + " not supported!");
}
diff --git a/source/Indy.IL2CPU.IL.X86/Conv_I8.cs b/source/Indy.IL2CPU.IL.X86/Conv_I8.cs
index abb7837f3..6686dd4a4 100644
--- a/source/Indy.IL2CPU.IL.X86/Conv_I8.cs
+++ b/source/Indy.IL2CPU.IL.X86/Conv_I8.cs
@@ -16,16 +16,15 @@ namespace Indy.IL2CPU.IL.X86 {
switch (xSource.Size) {
case 1:
case 2:
- case 4: {
- new CPUx86.Pop(CPUx86.Registers.EAX);
- new CPUx86.Pushd("0");
- new CPUx86.Pushd(CPUx86.Registers.EAX);
- break;
- }
- case 8: {
- new CPUx86.Noop();
- break;
- }
+ case 4:
+ new CPUx86.Pop(CPUx86.Registers.EAX);
+ new CPUx86.SignExtendAX(4);
+ new CPUx86.Pushd("EDX");
+ new CPUx86.Pushd("EAX");
+ break;
+ case 8:
+ new CPUx86.Noop();
+ break;
default:
throw new Exception("SourceSize " + xSource + " not supported!");
}
diff --git a/source/Indy.IL2CPU.IL.X86/Conv_Ovf_I.cs b/source/Indy.IL2CPU.IL.X86/Conv_Ovf_I.cs
index 6e7f3d8e6..6081aaf13 100644
--- a/source/Indy.IL2CPU.IL.X86/Conv_Ovf_I.cs
+++ b/source/Indy.IL2CPU.IL.X86/Conv_Ovf_I.cs
@@ -1,17 +1,46 @@
using System;
using System.IO;
-
-
-using CPU = Indy.IL2CPU.Assembler.X86;
+using CPU = Indy.IL2CPU.Assembler;
+using Indy.IL2CPU.Assembler;
+using CPUx86 = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(OpCodeEnum.Conv_Ovf_I)]
public class Conv_Ovf_I: Op {
+ private readonly string NextInstructionLabel;
public Conv_Ovf_I(ILReader aReader, MethodInformation aMethodInfo)
: base(aReader, aMethodInfo) {
+ NextInstructionLabel = GetInstructionLabel(aReader.NextPosition);
}
public override void DoAssemble() {
- throw new NotImplementedException("This file has been autogenerated and not been changed afterwards!");
+ var xSource = Assembler.StackContents.Pop();
+ switch (xSource.Size)
+ {
+ case 1:
+ case 2:
+ case 4:
+ {
+ new CPUx86.Noop();
+ break;
+ }
+ case 8:
+ {
+ new CPUx86.Pop(CPUx86.Registers.EAX);
+ new CPUx86.SignExtendAX(4);
+ //all bits of EDX == sign (EAX)
+ new CPUx86.Pop("EBX");
+ //must be equal to EDX
+ new CPUx86.Xor("EBX", "EDX");
+ new CPUx86.JumpIfZero(NextInstructionLabel);
+ //equals
+ new CPUx86.Interrupt(CPUx86.Interrupt.INTO);
+ break;
+
+ }
+ default:
+ throw new Exception("SourceSize " + xSource + " not supported!");
+ }
+ Assembler.StackContents.Push(new StackContent(4, true, false, false));
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86/Op.cs b/source/Indy.IL2CPU.IL.X86/Op.cs
index 4d5e9552d..8fbe20184 100644
--- a/source/Indy.IL2CPU.IL.X86/Op.cs
+++ b/source/Indy.IL2CPU.IL.X86/Op.cs
@@ -258,13 +258,14 @@ namespace Indy.IL2CPU.IL.X86 {
{
throw new NotImplementedException();
Add(aAssembler);
- if (signed)
- {
- new CPUx86.Interrupt(CPUx86.Interrupt.INTO);
- } else
- {
- throw new NotImplementedException();
- }
+ throw new NotImplementedException();
+ //if (signed)
+ //{
+ // new CPUx86.Interrupt(CPUx86.Interrupt.INTO);
+ //} else
+ //{
+
+ //}
}
public static void Add(Assembler.Assembler aAssembler) {
StackContent xSize = aAssembler.StackContents.Pop();