Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        protected override void Compile(CodeContext c)
        {
            var v0  = c.Int32("v0");
            var v1  = c.Int32("v1");
            var cnt = c.Int32("cnt");

            c.Xor(v0, v0);
            c.Xor(v1, v1);
            c.Spill(v0);
            c.Spill(v1);

            var l = c.Label();

            c.Mov(cnt, 32);
            c.Bind(l);

            c.Inc(v1);
            c.Add(v0, v1);

            c.Dec(cnt);
            c.Jnz(l);

            c.Ret(v0);
        }
Exemplo n.º 4
0
        protected override void Compile(CodeContext c)
        {
            var l1 = c.Label();

            var iIdx = c.Int32("iIdx");
            var iEnd = c.Int32("iEnd");

            var aIdx = c.Int32("aIdx");
            var aEnd = c.Int32("aEnd");

            c.SetArgument(0, aIdx);
            c.SetArgument(1, aEnd);

            c.Mov(iIdx, aIdx);
            c.Mov(iEnd, aEnd);
            c.Spill(iEnd);

            c.Bind(l1);
            c.Inc(iIdx);
            c.Cmp(iIdx, iEnd.ToMemory());
            c.Jne(l1);

            c.Ret(iIdx);
        }