Ejemplo n.º 1
0
        protected override void Compile(CodeContext c)
        {
            var a = c.Int32("a");
            var b = c.Int32("b");
            var r = c.Int32("r");

            c.SetArgument(0, a);
            c.SetArgument(1, b);

            c.Allocate(a, Cpu.Registers.Eax);
            c.Allocate(b, Cpu.Registers.Ebx);

            var call = c.Call(Memory.Fn(new Action <int, int>(CalledFunction)));

            call.SetArgument(0, a);
            call.SetArgument(1, b);

            c.Lea(r, Memory.Ptr(a, b));
            c.Ret(r);
        }
Ejemplo n.º 2
0
        protected override void Compile(CodeContext c)
        {
            var val  = c.Int32("val");
            var skip = c.Label();

            c.SetArgument(0, val);

            c.Cmp(val, 1);
            c.Jle(skip);

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

            c.Mov(tmp, val);
            c.Dec(tmp);

            var call = c.Call(c.Entry);

            call.SetArgument(0, tmp);
            call.SetReturn(0, tmp);
            c.Mul(c.Int32(), val, tmp);

            c.Bind(skip);
            c.Ret(val);
        }