From b4e746fcf8a501995ddb0c2bcb659f8a448869a2 Mon Sep 17 00:00:00 2001 From: AtomOS_cp <5a25c3af533aeff42bf19dd158c40bd93df49730ThEKjtWF> Date: Wed, 11 Jun 2014 05:38:33 +0000 Subject: [PATCH] Made Dup IL working for stack content size greater than 4 --- source2/IL2CPU/Cosmos.IL2CPU/IL/Dup.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/source2/IL2CPU/Cosmos.IL2CPU/IL/Dup.cs b/source2/IL2CPU/Cosmos.IL2CPU/IL/Dup.cs index cee43d97e..7e3d380aa 100644 --- a/source2/IL2CPU/Cosmos.IL2CPU/IL/Dup.cs +++ b/source2/IL2CPU/Cosmos.IL2CPU/IL/Dup.cs @@ -3,24 +3,25 @@ using CPUx86 = Cosmos.Assembler.x86; namespace Cosmos.IL2CPU.X86.IL { - [Cosmos.IL2CPU.OpCode( ILOpCode.Code.Dup )] + [Cosmos.IL2CPU.OpCode(ILOpCode.Code.Dup)] public class Dup : ILOp { - public Dup( Cosmos.Assembler.Assembler aAsmblr ) - : base( aAsmblr ) + public Dup(Cosmos.Assembler.Assembler aAsmblr) + : base(aAsmblr) { } - public override void Execute( MethodInfo aMethod, ILOpCode aOpCode ) + public override void Execute(MethodInfo aMethod, ILOpCode aOpCode) { var xStackContent = Assembler.Stack.Peek(); - for( int i = 0; i < ( ( xStackContent.Size / 4 ) + ( xStackContent.Size % 4 == 0 ? 0 : 1 ) ); i++ ) + var StackSize = (int)((xStackContent.Size / 4) + (xStackContent.Size % 4 == 0 ? 0 : 1)); + + for (int i = StackSize; i > 0; i--) { - new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.ESP, SourceDisplacement = i * 4, SourceIsIndirect = true }; - new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX }; + new CPUx86.Push { DestinationReg = CPUx86.Registers.ESP, DestinationIsIndirect = true, DestinationDisplacement = (int)((StackSize - 1) * 4) }; } Assembler.Stack.Push(xStackContent.Size, xStackContent.ContentType); } } -} +} \ No newline at end of file