Cosmos/source/Indy.IL2CPU/IL/x86/Div.cs
mterwoord_cp 5928581f2f
2008-11-07 12:27:08 +00:00

35 lines
No EOL
1.3 KiB
C#

using System;
using CPUx86 = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(OpCodeEnum.Div)]
public class Div: Op {
public Div(ILReader aReader, MethodInformation aMethodInfo)
: base(aReader, aMethodInfo) {
}
public override void DoAssemble() {
var xSize = Assembler.StackContents.Pop();
if (xSize.IsFloat) {
throw new Exception("Floats not yet supported!");
}
if (xSize.Size == 8) {
//TODO: implement proper div support for 8byte values!
new CPUx86.Xor(CPUx86.Registers_Old.EDX, CPUx86.Registers_Old.EDX);
new CPUx86.Pop { DestinationReg = CPUx86.Registers.ECX };
new CPUx86.Add { DestinationReg = CPUx86.Registers.ESP, SourceValue = 4 };
new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX };
new CPUx86.IDivide(CPUx86.Registers_Old.ECX);
//new CPUx86.Push("0");
new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX };
} else {
new CPUx86.Xor(CPUx86.Registers_Old.EDX, CPUx86.Registers_Old.EDX);
new CPUx86.Pop { DestinationReg = CPUx86.Registers.ECX };
new CPUx86.Pop{DestinationReg = CPUx86.Registers.EAX};
new CPUx86.IDivide(CPUx86.Registers_Old.ECX);
new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX };
}
}
}
}