4 static jit_state_t *_jit;
6 typedef int (*pifi)(int); /* Pointer to Int Function of Int */
8 int main(int argc, char *argv[])
11 jit_node_t *in; /* offset of the argument */
12 jit_node_t *ref; /* to patch the forward reference */
13 jit_node_t *zero; /* to patch the forward reference */
14 jit_node_t *jump; /* jump to start of loop */
15 jit_node_t *loop; /* start of the loop */
18 _jit = jit_new_state();
22 jit_getarg (JIT_R0, in); /* R0 = n */
23 zero = jit_beqi (JIT_R0, 0);
24 jit_movr (JIT_R1, JIT_R0);
26 ref = jit_blei (JIT_R1, 2);
27 jit_subi (JIT_R2, JIT_R1, 2);
28 jit_movr (JIT_R1, JIT_R0);
31 jit_subi (JIT_R2, JIT_R2, 1); /* decr. counter */
32 jit_movr (JIT_V0, JIT_R0); /* V0 = R0 */
33 jit_addr (JIT_R0, JIT_R0, JIT_R1); /* R0 = R0 + R1 */
34 jit_movr (JIT_R1, JIT_V0); /* R1 = V0 */
35 jump= jit_bnei (JIT_R2, 0); /* if (R2) goto loop; */
36 jit_patch_at(jump, loop);
38 jit_patch(ref); /* patch forward jump */
39 jit_patch(zero); /* patch forward jump */
42 /* call the generated code, passing 36 as an argument */
45 printf("fib(%d) = %d\n", 36, fib(36));