diff --git a/source/Indy.IL2CPU.IL.X86/Box.cs b/source/Indy.IL2CPU.IL.X86/Box.cs index 55f1c2f46..d4aa02053 100644 --- a/source/Indy.IL2CPU.IL.X86/Box.cs +++ b/source/Indy.IL2CPU.IL.X86/Box.cs @@ -31,11 +31,15 @@ namespace Indy.IL2CPU.IL.X86 { } public override void DoAssemble() { - new CPUx86.Pushd("0x" + (ObjectImpl.FieldDataOffset + mTheSize + (4 - (mTheSize % 4))).ToString("X").ToUpper()); + int xSize = mTheSize; + if (mTheSize % 4 != 0) { + xSize += 4 - (mTheSize % 4); + } + new CPUx86.Pushd("0x" + (ObjectImpl.FieldDataOffset + xSize).ToString("X").ToUpper()); new CPUx86.Call(CPU.Label.GenerateLabelName(RuntimeEngineRefs.Heap_AllocNewObjectRef)); new CPUx86.Move("dword", CPUx86.Registers.AtEAX, "0x" + mTypeId.ToString("X")); new CPUx86.Move("dword", "[eax + 4]", "0x" + InstanceTypeEnum.BoxedValueType.ToString("X")); - for (int i = 0; i < ((mTheSize + (4 - (mTheSize % 4))) / 4); i++) { + for (int i = 0; i < (xSize / 4); i++) { new CPUx86.Pop(CPUx86.Registers.EDX); new CPUx86.Move("dword", "[eax + 0x" + (ObjectImpl.FieldDataOffset + (i * 4)).ToString("X") + "]", "edx"); } diff --git a/source/Indy.IL2CPU.IL.X86/Isinst.cs b/source/Indy.IL2CPU.IL.X86/Isinst.cs index a8c8cfc36..ecabcbb16 100644 --- a/source/Indy.IL2CPU.IL.X86/Isinst.cs +++ b/source/Indy.IL2CPU.IL.X86/Isinst.cs @@ -29,24 +29,24 @@ namespace Indy.IL2CPU.IL.X86 { public override void DoAssemble() { string mReturnNullLabel = mThisLabel + "_ReturnNull"; - new CPUx86.Pop(CPUx86.Registers.EAX); + new CPUx86.Move(CPUx86.Registers.EAX, CPUx86.Registers.AtESP); new CPUx86.Compare(CPUx86.Registers.EAX, "0"); new CPUx86.JumpIfZero(mReturnNullLabel); - new CPUx86.Pushd(CPUx86.Registers.AtEAX, "0" + mTypeId + "h"); + new CPUx86.Pushd(CPUx86.Registers.AtEAX); + new CPUx86.Pushd("0" + mTypeId + "h"); + Assembler.StackContents.Push(new StackContent(4, typeof(object))); Assembler.StackContents.Push(new StackContent(4, typeof(object))); MethodBase xMethodIsInstance = Engine.GetMethodBase(typeof(VTablesImpl), "IsInstance", "System.Int32", "System.Int32"); Engine.QueueMethod(xMethodIsInstance); Op xOp = new Call(xMethodIsInstance, mCurrentILOffset); xOp.Assembler = Assembler; xOp.Assemble(); - new CPUx86.Pop(CPUx86.Registers.EAX); Assembler.StackContents.Pop(); + new CPUx86.Pop(CPUx86.Registers.EAX); new CPUx86.Compare(CPUx86.Registers.EAX, "0"); - new CPUx86.JumpIfEquals(mReturnNullLabel); - new CPUx86.Pushd(CPUx86.Registers.EAX); - new CPUx86.JumpAlways(mNextOpLabel); + new CPUx86.JumpIfNotEquals(mNextOpLabel); new CPU.Label(mReturnNullLabel); - Assembler.StackContents.Push(new StackContent(1, typeof(bool))); + new CPUx86.Add("esp", "4"); new CPUx86.Pushd("0"); } }