4 static jit_state_t *_jit;
6 typedef int (*pifi)(int); /* Pointer to Int Function of Int */
8 int main(int argc, char *argv[])
13 jit_node_t *in; /* offset of the argument */
14 jit_node_t *ref; /* to patch the forward reference */
15 jit_node_t *zero; /* to patch the forward reference */
18 _jit = jit_new_state();
23 jit_getarg (JIT_R0, in); /* R0 = n */
24 zero = jit_beqi (JIT_R0, 0);
25 jit_movr (JIT_V0, JIT_R0); /* V0 = R0 */
27 ref = jit_blei (JIT_V0, 2);
28 jit_subi (JIT_V1, JIT_V0, 1); /* V1 = n-1 */
29 jit_subi (JIT_V2, JIT_V0, 2); /* V2 = n-2 */
32 call = jit_finishi(NULL);
33 jit_patch_at(call, label);
34 jit_retval(JIT_V1); /* V1 = fib(n-1) */
37 call = jit_finishi(NULL);
38 jit_patch_at(call, label);
39 jit_retval(JIT_R0); /* R0 = fib(n-2) */
40 jit_addr(JIT_R0, JIT_R0, JIT_V1); /* R0 = R0 + V1 */
42 jit_patch(ref); /* patch jump */
43 jit_patch(zero); /* patch jump */
46 /* call the generated code, passing 32 as an argument */
49 printf("fib(%d) = %d\n", 32, fib(32));