Exemple #1
0
        protected override void Compile(CodeContext c)
        {
            var stack = c.Stack(256, 1).SetSize(1);
            var i     = c.IntPtr("i");
            var a     = c.Int32("a");
            var b     = c.Int32("b");

            var l1 = c.Label();
            var l2 = c.Label();

            // Fill stack by sequence [0, 1, 2, 3 ... 255].
            c.Xor(i, i);

            c.Bind(l1);
            c.Mov(stack.Clone().SetIndex(i), i.As8());
            c.Inc(i);
            c.Cmp(i, 255);
            c.Jle(l1);

            // Sum sequence in stack.
            c.Xor(i, i);
            c.Xor(a, a);

            c.Bind(l2);
            c.Movzx(b, stack.Clone().SetIndex(i));
            c.Add(a, b);
            c.Inc(i);
            c.Cmp(i, 255);
            c.Jle(l2);

            c.Ret(a);
        }
Exemple #2
0
        protected override void Compile(CodeContext c)
        {
            var v1 = c.Int32("v1");
            var v2 = c.Int32("v2");

            c.SetArgument(0, v1);
            c.SetArgument(1, v2);

            var counter = c.Int32("counter");

            var l1   = c.Label();
            var loop = c.Label();
            var exit = c.Label();

            c.Cmp(v1, v2);
            c.Jg(l1);

            c.Mov(counter, 0);

            c.Bind(loop);
            c.Mov(v1, counter);

            c.Inc(counter);
            c.Cmp(counter, 1);
            c.Jle(loop);
            c.Jmp(exit);

            c.Bind(l1);
            c.Mov(v1, 2);

            c.Bind(exit);
            c.Ret(v1);
        }