From 4aa8fcce86278e117c2cb5cd6709cd94e5ea63b7 Mon Sep 17 00:00:00 2001 From: LostTheBlack_cp Date: Sat, 15 Mar 2008 09:02:05 +0000 Subject: [PATCH] Int64: [+] equality comparing [+] add operation Int32: [*] Fixed bge instruction --- source/Boot/TestSuite/Tests/MathTest.cs | 8 ++--- .../Indy.IL2CPU.Assembler.X86.csproj | 1 + .../JumpIfNotZero.cs | 23 ++++++++++++++ source/Indy.IL2CPU.IL.X86/Bge.cs | 22 ++++++------- source/Indy.IL2CPU.IL.X86/Ceq.cs | 28 +++++++++++------ source/Tests/MathTest/LongArithmetics.cs | 31 +++++++++++++++++++ .../MathTest/{Program.cs => MathTest.cs} | 11 ++++--- source/Tests/MathTest/MathTest.csproj | 17 ++++++++-- 8 files changed, 109 insertions(+), 32 deletions(-) create mode 100644 source/Indy.IL2CPU.Assembler.X86/JumpIfNotZero.cs create mode 100644 source/Tests/MathTest/LongArithmetics.cs rename source/Tests/MathTest/{Program.cs => MathTest.cs} (78%) diff --git a/source/Boot/TestSuite/Tests/MathTest.cs b/source/Boot/TestSuite/Tests/MathTest.cs index 7ca778132..15fedb583 100644 --- a/source/Boot/TestSuite/Tests/MathTest.cs +++ b/source/Boot/TestSuite/Tests/MathTest.cs @@ -29,10 +29,10 @@ namespace TestSuite.Tests Assert(5 - 2 == 3, "5 - 2 == 3"); Assert(2 + 5 * 2 == 12, "2 + 5 * 2 == 12"); Assert((2 + 5) * 2 == 14, "(2 + 5) * 2 == 14"); - //long al = 0x1FFFFFFFF; - //long bl = 0x1FFFFFFFF;//1L; - ////al += bl; - //Assert(al == bl, "Int64 Equality"); + long al = 0x1FFFFFFFF; + long bl = 0x20;//1L; + Assert(al != bl, "Int64 Inequality"); + Assert(0x1FFFFFFFF + 0x01L == 0x200000000, "0x1FFFFFFFF + 0x01L == 0x200000000"); UInt32 a = 5; UInt32 b = 5; diff --git a/source/Indy.IL2CPU.Assembler.X86/Indy.IL2CPU.Assembler.X86.csproj b/source/Indy.IL2CPU.Assembler.X86/Indy.IL2CPU.Assembler.X86.csproj index 3efd3a97a..db602afbf 100644 --- a/source/Indy.IL2CPU.Assembler.X86/Indy.IL2CPU.Assembler.X86.csproj +++ b/source/Indy.IL2CPU.Assembler.X86/Indy.IL2CPU.Assembler.X86.csproj @@ -60,6 +60,7 @@ + diff --git a/source/Indy.IL2CPU.Assembler.X86/JumpIfNotZero.cs b/source/Indy.IL2CPU.Assembler.X86/JumpIfNotZero.cs new file mode 100644 index 000000000..c16aad4e8 --- /dev/null +++ b/source/Indy.IL2CPU.Assembler.X86/JumpIfNotZero.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Indy.IL2CPU.Assembler.X86 +{ + /// + /// Represents the JNZ opcode + /// + [OpCode(0xFFFFFFFF, "jnz")] + public class JumpIfNotZero : JumpBase + { + public JumpIfNotZero(string aAddress) + : base(aAddress) + { + } + public override string ToString() + { + return "jnz " + Address; + } + } +} diff --git a/source/Indy.IL2CPU.IL.X86/Bge.cs b/source/Indy.IL2CPU.IL.X86/Bge.cs index 904f4ef66..d8b80310f 100644 --- a/source/Indy.IL2CPU.IL.X86/Bge.cs +++ b/source/Indy.IL2CPU.IL.X86/Bge.cs @@ -24,22 +24,22 @@ namespace Indy.IL2CPU.IL.X86 { #warning Code checking: strange code seems to be generated. Read the following comments: //JumpAlways right after JumpIfGreaterOrEquals to the same label //my offer is: - //new CPUx86.Pop(CPUx86.Registers.EAX); - //new CPUx86.Pop(CPUx86.Registers.EBX); - //new CPUx86.JumpIfGreaterOrEquals(LabelTrue); - //new CPUx86.JumpAlways(LabelFalse); - //new CPU.Label(LabelTrue); - //new CPU.JumpAlways(TargetLabel); - //new CPU.Label(LabelFalse); new CPUx86.Pop(CPUx86.Registers.EAX); - new CPUx86.Compare(CPUx86.Registers.EAX, CPUx86.Registers.AtESP); + new CPUx86.Pop(CPUx86.Registers.EBX); new CPUx86.JumpIfGreaterOrEquals(LabelTrue); - new CPUx86.JumpAlways(LabelTrue); + new CPUx86.JumpAlways(LabelFalse); new CPU.Label(LabelTrue); - new CPUx86.Add(CPUx86.Registers.ESP, "4"); new CPUx86.JumpAlways(TargetLabel); new CPU.Label(LabelFalse); - new CPUx86.Add(CPUx86.Registers.ESP, "4"); + //new CPUx86.Pop(CPUx86.Registers.EAX); + //new CPUx86.Compare(CPUx86.Registers.EAX, CPUx86.Registers.AtESP); + //new CPUx86.JumpIfGreaterOrEquals(LabelTrue); + //new CPUx86.JumpAlways(LabelTrue); + //new CPU.Label(LabelTrue); + //new CPUx86.Add(CPUx86.Registers.ESP, "4"); + //new CPUx86.JumpAlways(TargetLabel); + //new CPU.Label(LabelFalse); + //new CPUx86.Add(CPUx86.Registers.ESP, "4"); } private void DoAssemble64Bit() { diff --git a/source/Indy.IL2CPU.IL.X86/Ceq.cs b/source/Indy.IL2CPU.IL.X86/Ceq.cs index afbdecfd8..bc126fbb3 100644 --- a/source/Indy.IL2CPU.IL.X86/Ceq.cs +++ b/source/Indy.IL2CPU.IL.X86/Ceq.cs @@ -39,19 +39,27 @@ namespace Indy.IL2CPU.IL.X86 { string BaseLabel = CurInstructionLabel + "__"; string LabelTrue = BaseLabel + "True"; string LabelFalse = BaseLabel + "False"; + new CPUx86.Pop(CPUx86.Registers.EAX); - new CPUx86.Add("esp", "4"); - new CPUx86.Compare(CPUx86.Registers.EAX, CPUx86.Registers.AtESP); - new CPUx86.JumpIfEquals(LabelTrue); - new CPUx86.JumpAlways(LabelFalse); - new CPU.Label(LabelTrue); - new CPUx86.Add(CPUx86.Registers.ESP, "4"); - new CPUx86.Add("esp", "4"); + new CPUx86.Compare(CPUx86.Registers.EAX, "[esp + 4]"); + + new CPUx86.Pop(CPUx86.Registers.EAX); + new CPUx86.JumpIfNotEquals(LabelFalse); + + new CPUx86.Xor(CPUx86.Registers.EAX, "[esp + 4]"); + new CPUx86.JumpIfNotZero(LabelFalse); + + //they are equal, eax == 0 + new CPUx86.Add(CPUx86.Registers.ESP, "8"); + new CPUx86.Add(CPUx86.Registers.EAX, "1"); + new CPUx86.Push(CPUx86.Registers.EAX); new CPUx86.JumpAlways(NextInstructionLabel); + new CPU.Label(LabelFalse); - new CPUx86.Add(CPUx86.Registers.ESP, "4"); - new CPUx86.Add("esp", "4"); - new CPUx86.Push("00h"); + //eax = 0 + new CPUx86.Add(CPUx86.Registers.ESP, "8"); + new CPUx86.Xor(CPUx86.Registers.EAX, CPUx86.Registers.EAX); + new CPUx86.Push(CPUx86.Registers.EAX); new CPUx86.JumpAlways(NextInstructionLabel); } diff --git a/source/Tests/MathTest/LongArithmetics.cs b/source/Tests/MathTest/LongArithmetics.cs new file mode 100644 index 000000000..e3078d84e --- /dev/null +++ b/source/Tests/MathTest/LongArithmetics.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MathTest +{ + class LongArithmetics + { + public static void Test() + { + Console.WriteLine("+++LongArithmeticsTest+++"); + + Console.Write("carry test..."); + long a = 0x1FFFFFFFFL; + long b = 1; + + if (a + b != 0x200000000L) + { + Console.WriteLine("failed"); + Console.Write("excepted: "); + Console.WriteLine((0x200000000L).ToString()); + Console.Write("received: "); + Console.WriteLine((a + b).ToString()); + } else + Console.WriteLine("passed"); + + + Console.WriteLine(""); + } + } +} diff --git a/source/Tests/MathTest/Program.cs b/source/Tests/MathTest/MathTest.cs similarity index 78% rename from source/Tests/MathTest/Program.cs rename to source/Tests/MathTest/MathTest.cs index 6d7af933a..11da59d73 100644 --- a/source/Tests/MathTest/Program.cs +++ b/source/Tests/MathTest/MathTest.cs @@ -3,7 +3,7 @@ using Cosmos.Build.Windows; namespace MathTest { - class Program + class MathTest { #region Cosmos Builder logic // Most users wont touch this. This will call the Cosmos Build tool @@ -18,10 +18,13 @@ namespace MathTest // Main entry point of the kernel public static void Init() { - //Cosmos.Kernel..CPU.Init(); + Cosmos.Kernel.Boot.Default(); Console.WriteLine("Done booting"); + + LongArithmetics.Test(); + while (true) - ; + ; } } -} \ No newline at end of file +} diff --git a/source/Tests/MathTest/MathTest.csproj b/source/Tests/MathTest/MathTest.csproj index f7cd0a1fe..c03a72b6f 100644 --- a/source/Tests/MathTest/MathTest.csproj +++ b/source/Tests/MathTest/MathTest.csproj @@ -36,14 +36,25 @@ 4 - - + + - + + + + + {1F0EDE86-F6D4-4355-9A97-10E90457770C} + Cosmos.Build.Windows + + + {A1F83D9F-2D44-4264-A08B-416797123018} + Cosmos.Kernel + +