[+] MoveAndSignExtend & MoveAndZeroExtend added to assmebler

[+] SignExtendAX to handle AX -> DX:AX & EAX -> EDX:EAX
[+] Conversion to int8
[*] Fixed conversion to int16
[*] Fixed conversion to int64
[+] Added conversion
[*] AddWithOverflow code fixed.
This commit is contained in:
LostTheBlack_cp 2008-04-18 13:29:13 +00:00
parent 6dd9d872ba
commit 1af5ac6f34
9 changed files with 170 additions and 37 deletions

View file

@ -70,6 +70,9 @@
<Compile Include="JumpIfGreaterOrEqual.cs" />
<Compile Include="JumpIfNotZero.cs" />
<Compile Include="JumpOnGreater.cs" />
<Compile Include="MoveAndSignExtend.cs" />
<Compile Include="MoveAndZeroExtend.cs" />
<Compile Include="SignExtendAX.cs" />
<Compile Include="Stosw.cs" />
<Compile Include="JumpNotCary.cs" />
<Compile Include="RepeatMovsb.cs" />

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}

View file

@ -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();
}
}
}
}

View file

@ -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));
}
}
}

View file

@ -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!");
}

View file

@ -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!");
}

View file

@ -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));
}
}
}

View file

@ -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();