Example #1
0
        public static void Main(String[] args)
        {
            ushort a = 0xffff;
              ushort b = 1;

              ushort copyA = a;
              Processor p = new Processor();
              p.add (ref a, ref b);
              Console.WriteLine(copyA + " + " + b + " = " + a);
              Console.WriteLine ("overflow: " + p.machine.o);

              a = 5;
              b = 10;
              copyA = a;
              p.add (ref a, ref b);
              Console.WriteLine(copyA + " + " + b + " = " + a);
              Console.WriteLine ("overflow: " + p.machine.o);

              a = 10;
              b = 5;
              copyA = a;
              p.sub (ref a, ref b);
              Console.WriteLine(copyA + " - " + b + " = " + a);
              Console.WriteLine ("overflow: " + p.machine.o);

              a = 5;
              b = 10;
              copyA = a;
              p.sub (ref a, ref b);
              Console.WriteLine(copyA + " - " + b + " = " + a);
              Console.WriteLine ("overflow: " + p.machine.o);

              a = 0xffff;
              b = 0x5;
              copyA = a;
              p.mul (ref a, ref b);
              Console.WriteLine(copyA + " * " + b + " = " + a);
              Console.WriteLine ("overflow: " + p.machine.o);

              a = 0xffff;
              b = 0xffff;
              copyA = a;
              p.mul (ref a, ref b);
              Console.WriteLine(copyA + " * " + b + " = " + a);
              Console.WriteLine ("overflow: " + p.machine.o);

              a = 0xf000;
              b = 2;
              copyA = a;
              p.div (ref a, ref b);
              Console.WriteLine(copyA + " / " + b + " = " + a);
              Console.WriteLine ("overflow: " + p.machine.o);

              a = 0xf001;
              b = 2;
              copyA = a;
              p.div (ref a, ref b);
              Console.WriteLine(copyA + " / " + b + " = " + a);
              Console.WriteLine ("overflow: " + p.machine.o);

              a = 0xf001;
              b = 14;
              copyA = a;
              p.div (ref a, ref b);
              Console.WriteLine(copyA + " / " + b + " = " + a);
              Console.WriteLine ("overflow: " + p.machine.o);

              a = 0x8000;
              b = 2;
              copyA = a;
              p.mod (ref a, ref b);
              Console.WriteLine(copyA + " % " + b + " = " + a);
              Console.WriteLine ("overflow: " + p.machine.o);

              a = 0x8001;
              b = 2;
              copyA = a;
              p.mod (ref a, ref b);
              Console.WriteLine(copyA + " % " + b + " = " + a);
              Console.WriteLine ("overflow: " + p.machine.o);

              a = 0xf001;
              b = 2;
              copyA = a;
              p.shl (ref a, ref b);
              Console.WriteLine(copyA + " << " + b + " = " + a);
              Console.WriteLine ("overflow: " + p.machine.o);

              a = 0xf007;
              b = 2;
              copyA = a;
              p.shr (ref a, ref b);
              Console.WriteLine(copyA + " >> " + b + " = " + a);
              Console.WriteLine ("overflow: " + p.machine.o);

              a = 0xf007;
              b = 0x0f08;
              copyA = a;
              p.and (ref a, ref b);
              Console.WriteLine(copyA + " & " + b + " = " + a);
              Console.WriteLine ("overflow: " + p.machine.o);

              a = 0xf007;
              b = 0x0f09;
              copyA = a;
              p.or (ref a, ref b);
              Console.WriteLine(copyA + " | " + b + " = " + a);
              Console.WriteLine ("overflow: " + p.machine.o);

              a = 0xf007;
              b = 0x0f09;
              copyA = a;
              p.xor (ref a, ref b);
              Console.WriteLine(copyA + " xor " + b + " = " + a);
              Console.WriteLine ("overflow: " + p.machine.o);
        }
Example #2
0
        public static void Main(String[] args)
        {
            ushort[] sample = {
            0x7c01, 0x0030, 0x7de1, 0x1000, 0x0020, 0x7803, 0x1000, 0xc00d,
            0x7dc1, 0x001a, 0xa861, 0x7c01, 0x2000, 0x2161, 0x2000, 0x8463,
            0x806d, 0x7dc1, 0x000d, 0x9031, 0x7c10, 0x0018, 0x7dc1, 0x001a,
            0x9037, 0x61c1, 0x7dc1, 0x001a, 0x0000, 0x0000, 0x0000, 0x0000
            };

              Machine m1 = new Machine();
              for (int i = 0; i < sample.Length; ++i)
              {
            m1.ram[i] = sample[i];
              }

              Processor p1 = new Processor(m1);

              while (m1.pc != 0x1a)
              {
            p1.DoCycle();
              }

              ushort a = 0xffff;
              ushort b = 1;

              ushort copyA = a;
              Processor p = new Processor();
              p.add(ref a, new Lazy<ushort>(() => b));
              Console.WriteLine(copyA + " + " + b + " = " + a);
              Console.WriteLine("overflow: " + p.machine.o);

              a = 5;
              b = 10;
              copyA = a;
              p.add(ref a, new Lazy<ushort>(() => b));
              Console.WriteLine(copyA + " + " + b + " = " + a);
              Console.WriteLine("overflow: " + p.machine.o);

              a = 10;
              b = 5;
              copyA = a;
              p.sub(ref a, new Lazy<ushort>(() => b));
              Console.WriteLine(copyA + " - " + b + " = " + a);
              Console.WriteLine("overflow: " + p.machine.o);

              a = 5;
              b = 10;
              copyA = a;
              p.sub(ref a, new Lazy<ushort>(() => b));
              Console.WriteLine(copyA + " - " + b + " = " + a);
              Console.WriteLine("overflow: " + p.machine.o);

              a = 0xffff;
              b = 0x5;
              copyA = a;
              p.mul(ref a, new Lazy<ushort>(() => b));
              Console.WriteLine(copyA + " * " + b + " = " + a);
              Console.WriteLine("overflow: " + p.machine.o);

              a = 0xffff;
              b = 0xffff;
              copyA = a;
              p.mul(ref a, new Lazy<ushort>(() => b));
              Console.WriteLine(copyA + " * " + b + " = " + a);
              Console.WriteLine("overflow: " + p.machine.o);

              a = 0xf000;
              b = 2;
              copyA = a;
              p.div(ref a, new Lazy<ushort>(() => b));
              Console.WriteLine(copyA + " / " + b + " = " + a);
              Console.WriteLine("overflow: " + p.machine.o);

              a = 0xf001;
              b = 2;
              copyA = a;
              p.div(ref a, new Lazy<ushort>(() => b));
              Console.WriteLine(copyA + " / " + b + " = " + a);
              Console.WriteLine("overflow: " + p.machine.o);

              a = 0xf001;
              b = 14;
              copyA = a;
              p.div(ref a, new Lazy<ushort>(() => b));
              Console.WriteLine(copyA + " / " + b + " = " + a);
              Console.WriteLine("overflow: " + p.machine.o);

              a = 0x8000;
              b = 2;
              copyA = a;
              p.mod(ref a, new Lazy<ushort>(() => b));
              Console.WriteLine(copyA + " % " + b + " = " + a);
              Console.WriteLine("overflow: " + p.machine.o);

              a = 0x8001;
              b = 2;
              copyA = a;
              p.mod(ref a, new Lazy<ushort>(() => b));
              Console.WriteLine(copyA + " % " + b + " = " + a);
              Console.WriteLine("overflow: " + p.machine.o);

              a = 0xf001;
              b = 2;
              copyA = a;
              p.shl(ref a, new Lazy<ushort>(() => b));
              Console.WriteLine(copyA + " << " + b + " = " + a);
              Console.WriteLine("overflow: " + p.machine.o);

              a = 0xf007;
              b = 2;
              copyA = a;
              p.shr(ref a, new Lazy<ushort>(() => b));
              Console.WriteLine(copyA + " >> " + b + " = " + a);
              Console.WriteLine("overflow: " + p.machine.o);

              a = 0xf007;
              b = 0x0f08;
              copyA = a;
              p.and(ref a, new Lazy<ushort>(() => b));
              Console.WriteLine(copyA + " & " + b + " = " + a);
              Console.WriteLine("overflow: " + p.machine.o);

              a = 0xf007;
              b = 0x0f09;
              copyA = a;
              p.or(ref a, new Lazy<ushort>(() => b));
              Console.WriteLine(copyA + " | " + b + " = " + a);
              Console.WriteLine("overflow: " + p.machine.o);

              a = 0xf007;
              b = 0x0f09;
              copyA = a;
              p.xor(ref a, new Lazy<ushort>(() => b));
              Console.WriteLine(copyA + " xor " + b + " = " + a);
              Console.WriteLine("overflow: " + p.machine.o);
        }