diff --git a/source2/Compiler/Cosmos.Compiler.Assembler.X86/Cosmos.Compiler.Assembler.X86.csproj b/source2/Compiler/Cosmos.Compiler.Assembler.X86/Cosmos.Compiler.Assembler.X86.csproj index 5fd3eca20..d60ba8960 100644 --- a/source2/Compiler/Cosmos.Compiler.Assembler.X86/Cosmos.Compiler.Assembler.X86.csproj +++ b/source2/Compiler/Cosmos.Compiler.Assembler.X86/Cosmos.Compiler.Assembler.X86.csproj @@ -64,6 +64,7 @@ + diff --git a/source2/Compiler/Cosmos.Compiler.Assembler.X86/MoveZeroExtend.cs b/source2/Compiler/Cosmos.Compiler.Assembler.X86/MoveZeroExtend.cs new file mode 100644 index 000000000..4ad273a93 --- /dev/null +++ b/source2/Compiler/Cosmos.Compiler.Assembler.X86/MoveZeroExtend.cs @@ -0,0 +1,24 @@ +namespace Cosmos.Compiler.Assembler.X86 { + [OpCode("movzx")] + public class MoveZeroExtend : InstructionWithDestinationAndSourceAndSize + { + + public override void WriteText(Assembler aAssembler, System.IO.TextWriter aOutput) + { + if (Size == 0) + { + Size = 32; + } + aOutput.Write(mMnemonic); + if (!DestinationEmpty) + { + aOutput.Write(" "); + aOutput.Write(this.GetDestinationAsString()); + aOutput.Write(", "); + aOutput.Write(SizeToString(Size)); + aOutput.Write(" "); + aOutput.Write(this.GetSourceAsString()); + } + } + } +} \ No newline at end of file diff --git a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Ldloc.cs b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Ldloc.cs index bcef9d5ec..dc70ab26b 100644 --- a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Ldloc.cs +++ b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Ldloc.cs @@ -36,7 +36,11 @@ namespace Cosmos.IL2CPU.X86.IL case 1: case 2: { - new CPUx86.MoveSignExtend { DestinationReg = CPUx86.Registers.EAX, Size = (byte)(xSize * 8), SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0 - xEBPOffset }; + bool signed = IsIntegerSigned(xVar.LocalType); + if (signed) + new CPUx86.MoveSignExtend { DestinationReg = CPUx86.Registers.EAX, Size = (byte)(xSize * 8), SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0 - xEBPOffset }; + else + new CPUx86.MoveZeroExtend { DestinationReg = CPUx86.Registers.EAX, Size = (byte)(xSize * 8), SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = 0 - xEBPOffset }; new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX }; break; } diff --git a/source2/IL2CPU/Cosmos.IL2CPU.X86/ILOp.cs b/source2/IL2CPU/Cosmos.IL2CPU.X86/ILOp.cs index 0be1c6a27..60bd9ca5e 100644 --- a/source2/IL2CPU/Cosmos.IL2CPU.X86/ILOp.cs +++ b/source2/IL2CPU/Cosmos.IL2CPU.X86/ILOp.cs @@ -229,6 +229,21 @@ namespace Cosmos.IL2CPU.X86 { } } + public static bool IsIntegerSigned(Type aType) + { + switch (aType.FullName) + { + case "System.SByte": + case "System.Int16": + case "System.Int32": + case "System.Int64": + //TODO not sure about this case "System.IntPtr": + //TODO not sure aobut this case "System.Enum": + return true; + } + return false; + } + public static uint SizeOfType(Type aType) { if (aType.FullName == "System.Void")