mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-26 21:42:11 +00:00
add sign check for choose right asm instruction in LdLoc
This commit is contained in:
parent
96d3fde47c
commit
6f1efc4bcb
4 changed files with 45 additions and 1 deletions
|
|
@ -64,6 +64,7 @@
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="MoveZeroExtend.cs" />
|
||||||
<Compile Include="MoveSignExtend.cs" />
|
<Compile Include="MoveSignExtend.cs" />
|
||||||
<Compile Include="Lgdt.cs" />
|
<Compile Include="Lgdt.cs" />
|
||||||
<Compile Include="Lidt.cs" />
|
<Compile Include="Lidt.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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -36,7 +36,11 @@ namespace Cosmos.IL2CPU.X86.IL
|
||||||
case 1:
|
case 1:
|
||||||
case 2:
|
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 };
|
new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX };
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
public static uint SizeOfType(Type aType)
|
||||||
{
|
{
|
||||||
if (aType.FullName == "System.Void")
|
if (aType.FullName == "System.Void")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue